Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action Script string to number

I have a problem with following statement

trace(Number("1/2")) //output NaN

but

trace(Number("1.2")) //output 1.2

So, I am bit confused as why the first statement doesn't gives correct result?

like image 277
sameer jain Avatar asked Dec 17 '22 04:12

sameer jain


1 Answers

It probably expects the value to be a number already, not a calculation. Try to parse this string: "1+2". It'll most likely result in NaN as well.


Edit: I've run a test

Number("1.2") = 1.2
Number("1+2") = NaN
Number("1/2") = NaN

So, as I said, the Number() constructor expects a number, not a calculation.

like image 88
Tim S. Avatar answered Dec 22 '22 09:12

Tim S.