[flexcoders] Re: parseFloat vs Number

2007-10-31 Thread reflexactions
Thanks anyway for the reply, though I wasnt really asking what the 
difference is between Number and parseFloat I was asking more 
specifically about the difference between Number and parseFloats 
string parsing capabilities.


--- In flexcoders@yahoogroups.com, Abdul Qabiz [EMAIL PROTECTED] 
wrote:

 
  Is there anything that Number() parses that parseFloat doesnt?
 
 
 There are differences:-
 
 1) Number is type where as parseFloat () is a global-function
 2) Number (x) tries to cast x to Number where as parseFloat (x) 
reads, or *
 parses*, and returns the numbers in a string until it reaches a 
character.
 
 We use Number for typing, casting generally.
 
 Does that make sense?
 
 
 On 10/31/07, reflexactions [EMAIL PROTECTED] wrote:
 
Just looking at parsing strings into a Number i.e.
  parseFloat(string) or Number(string)
 
  It seems to me that parseFloat does everything Number does plus a
  little bit more (it will accept trailing non-numeric characters).
 
  Is there anything that Number() parses that parseFloat doesnt?
 
  tks
 
   
 
 
 
 
 -- 
 -abdul
 ---
 http://abdulqabiz.com/blog/
 ---





Re: [flexcoders] Re: parseFloat vs Number

2007-10-31 Thread Abdul Qabiz
AFAIK, Number  (x) would return NaN as soon as it finds any character that's
digit/number... Where as parseFloat (x) does some effort to find out the
number until it encounters NaN character...

-abdul

On 10/31/07, reflexactions [EMAIL PROTECTED] wrote:

   Thanks anyway for the reply, though I wasnt really asking what the
 difference is between Number and parseFloat I was asking more
 specifically about the difference between Number and parseFloats
 string parsing capabilities.

 --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Abdul
 Qabiz [EMAIL PROTECTED]
 wrote:
 
  
   Is there anything that Number() parses that parseFloat doesnt?
  
 
  There are differences:-
 
  1) Number is type where as parseFloat () is a global-function
  2) Number (x) tries to cast x to Number where as parseFloat (x)
 reads, or *
  parses*, and returns the numbers in a string until it reaches a
 character.
 
  We use Number for typing, casting generally.
 
  Does that make sense?
 
 
  On 10/31/07, reflexactions [EMAIL PROTECTED] wrote:
  
   Just looking at parsing strings into a Number i.e.
   parseFloat(string) or Number(string)
  
   It seems to me that parseFloat does everything Number does plus a
   little bit more (it will accept trailing non-numeric characters).
  
   Is there anything that Number() parses that parseFloat doesnt?
  
   tks
  
  
  
 
 
 
  --
  -abdul
  ---
  http://abdulqabiz.com/blog/
  ---
 

  




-- 
-abdul
---
http://abdulqabiz.com/blog/
---


[flexcoders] Re: parseFloat vs Number

2007-10-31 Thread johantrax
Well, sometimes to discover you ought to try ;)

I built you a little sample-application showing the results of
parseFloat and Number() (and 'as Number', which gives, lets say
'predictable', results when used on a String)

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
creationComplete=showNumbers()

mx:Script
![CDATA[
private function showNumbers():void
{
var stringNumbers:Array = [123, 12.3, 
1,23, 123abc,
abc123, 12ac3];

var output:String = ;
for (var s:String in stringNumbers) {
output += \nresult for  + 
stringNumbers[s] + :;
output += \n\tNumber():\t\t + 
Number(stringNumbers[s]);
output += \n\tparseFloat():\t + 
parseFloat(stringNumbers[s]);
output += \n\tas Number:\t + 
(stringNumbers[s] as Number);
output += \n;
}
results.text = output;
}
]]
/mx:Script

mx:Text id=results /
/mx:Application

--Johan


--- In flexcoders@yahoogroups.com, reflexactions [EMAIL PROTECTED]
wrote:

 Thanks anyway for the reply, though I wasnt really asking what the 
 difference is between Number and parseFloat I was asking more 
 specifically about the difference between Number and parseFloats 
 string parsing capabilities.




[flexcoders] Re: parseFloat vs Number

2007-10-31 Thread reflexactions
Yeah I did exactly that already, even before asking the question.
I was just asking the question of a larger group to see if there was 
something I might have missed before committing to overriding a 
function in an Adobe class that was just doing Number(string) :) 

It easy to write a test and then find out later there is some 
situation you overlooked that then invalidates your original small 
test.


--- In flexcoders@yahoogroups.com, johantrax [EMAIL PROTECTED] 
wrote:

 Well, sometimes to discover you ought to try ;)
 
 I built you a little sample-application showing the results of
 parseFloat and Number() (and 'as Number', which gives, lets say
 'predictable', results when used on a String)
 
 ?xml version=1.0 encoding=utf-8?
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
   creationComplete=showNumbers()
 
   mx:Script
   ![CDATA[
   private function showNumbers():void
   {
   var stringNumbers:Array = 
[123, 12.3, 1,23, 123abc,
 abc123, 12ac3];
   
   var output:String = ;
   for (var s:String in stringNumbers) {
   output += \nresult for  + 
stringNumbers[s] + :;
   output += \n\tNumber():\t\t 
+ Number(stringNumbers[s]);
   output += \n\tparseFloat
():\t + parseFloat(stringNumbers[s]);
   output += \n\tas Number:\t 
+ (stringNumbers[s] as Number);
   output += \n;
   }
   results.text = output;
   }
   ]]
   /mx:Script
   
   mx:Text id=results /
 /mx:Application
 
 --Johan
 
 
 --- In flexcoders@yahoogroups.com, reflexactions reflexactions@
 wrote:
 
  Thanks anyway for the reply, though I wasnt really asking what 
the 
  difference is between Number and parseFloat I was asking more 
  specifically about the difference between Number and parseFloats 
  string parsing capabilities.





[flexcoders] Re: parseFloat vs Number

2007-10-31 Thread johantrax
I agree that in most (if not all) cases, small tests indeed will skip
some situations (as did mine, i forgot the empty string)

But for most functions you can find solid documentation within the
language reference.
f.e. (under Global functions):

Number()function public function Number(expression:Object
http://livedocs.adobe.com/flex/2/langref/Object.html ):Number
http://livedocs.adobe.com/flex/2/langref/Number.html
Converts a given value to a Number value. The following table shows the
result of various input types:

Input Type/Value   Example   Return Value
undefined   Number(undefined)   NaN null  
Number(null)   0 true   Number(true)   1
false   Number(false)   0 NaN   Number(NaN)
NaN Empty string   Number()   0
String that converts to Number   Number(5)   The number (e.g.
5) String that does not convert to Number  
Number(5a)   NaN   Parameters
expression:Object http://livedocs.adobe.com/flex/2/langref/Object.html
— A value to be converted to a number.   Returns
Number http://livedocs.adobe.com/flex/2/langref/Number.html  —
The converted number value.
and a bit further:

parseFloat()function public function parseFloat(str:String
http://livedocs.adobe.com/flex/2/langref/String.html ):Number
http://livedocs.adobe.com/flex/2/langref/Number.html
Converts a string to a floating-point number. The function reads, or
parses, and returns the numbers in a string until it reaches a character
that is not a part of the initial number. If the string does not begin
with a number that can be parsed, parseFloat() returns NaN. White space
preceding valid integers is ignored, as are trailing nonnumeric
characters.
Parameters
str:String http://livedocs.adobe.com/flex/2/langref/String.html  —
The string to read and convert to a floating-point number.   Returns
Number http://livedocs.adobe.com/flex/2/langref/Number.html  —
A number or NaN (not a number).

So the differnce is that (as was posted here before) parseFloat tries
'harder' to return a Number than Number() does.

--Johan

--- In flexcoders@yahoogroups.com, reflexactions [EMAIL PROTECTED]
wrote:

 Yeah I did exactly that already, even before asking the question.
 I was just asking the question of a larger group to see if there was
 something I might have missed before committing to overriding a
 function in an Adobe class that was just doing Number(string) :)

 It easy to write a test and then find out later there is some
 situation you overlooked that then invalidates your original small
 test.


 --- In flexcoders@yahoogroups.com, johantrax johan.temmerman@
 wrote:
 
  Well, sometimes to discover you ought to try ;)
 
  I built you a little sample-application showing the results of
  parseFloat and Number() (and 'as Number', which gives, lets say
  'predictable', results when used on a String)
 
  ?xml version=1.0 encoding=utf-8?
  mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
   creationComplete=showNumbers()
  
   mx:Script
![CDATA[
 private function showNumbers():void
 {
  var stringNumbers:Array =
 [123, 12.3, 1,23, 123abc,
  abc123, 12ac3];
 
  var output:String = ;
  for (var s:String in stringNumbers) {
   output += \nresult for  +
 stringNumbers[s] + :;
   output += \n\tNumber():\t\t
 + Number(stringNumbers[s]);
   output += \n\tparseFloat
 ():\t + parseFloat(stringNumbers[s]);
   output += \n\tas Number:\t
 + (stringNumbers[s] as Number);
   output += \n;
  }
  results.text = output;
 }
]]
   /mx:Script
 
   mx:Text id=results /
  /mx:Application
 
  --Johan
 
 
  --- In flexcoders@yahoogroups.com, reflexactions reflexactions@
  wrote:
  
   Thanks anyway for the reply, though I wasnt really asking what
 the
   difference is between Number and parseFloat I was asking more
   specifically about the difference between Number and parseFloats
   string parsing capabilities.