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.
> >
>

Reply via email to