The parseFloat("0100", 10) solution and even the for-loop are likely to
perform better than using NumberFormatter, which executes much more general
code. But go with what you find simplest because performance won't be a
concern when dealing with user input.- Gordon -----Original Message----- From: Rich Tretola [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 08, 2005 5:33 AM To: [email protected] Subject: Re: [flexcoders] Hex Issue on a string to number cast? OK, so instead of doing the lengthly for loop, a simple number formatter did the trick. I am really suprised that someone from macromedia would offer such a lengthy solution. Here is the code that evaluates to 100.: <mx:NumberFormatter id="numberFormat" precision="2" rounding="nearest" decimalSeparatorFrom="." decimalSeparatorTo="." useThousandsSeparator="false" /> var testString 0100:String; var testNumber = Number(numberFormat.format(testString)); Rich On Mon, 7 Mar 2005 15:18:50 -0800, Gordon Smith <[EMAIL PROTECTED]> wrote: > > You could use a for-loop (rather than a recursive function) to strip > off leading 0's. > > - Gordon > > > -----Original Message----- > From: Rich Tretola [mailto:[EMAIL PROTECTED] > Sent: Monday, March 07, 2005 12:16 PM > To: [email protected] > Subject: [flexcoders] Hex Issue on a string to number cast? > > I have a text input that I am using as a free input field for a > number. I have it restricted to 0-9 characters and am casting it to a > number when setting the value to my object. The problem is that if > someone enters a value with a leading 0 such as 0100 it casts to 64. I > am assuming that this is seen as a hex value when casting. Is there > an easy way to avoid this without doing some crazy recursive string > functions checking each character until I am sure the 1st character is > not a 0 before the cast to Number() ? If someone enters 0100 by > mistake, it should be set as 100. > > Rich > > Yahoo! Groups Links > > Yahoo! Groups Links > > > > > Yahoo! Groups Links

