i am using eval to convert string decimals to decimals.
eval("000451.01");
When i am using the above statement javascript it throws exception ‘expected ;’
and when using eval("000451"); it gives me a different result.
anyone has got any idea??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should not use
evalto parse numbers; it will be orders of magnitude slower than normal methods.Instead, you should use the
parseFloatfunction. like this:parseFloat("000451.01").The reason you’re getting the error is that Javascript treats numbers that begin with
0as octal numbers, which cannot have decimals.If you want to parse an integer, call
parseInt, and make sure to give a second parameter of10to force it to parse base 10 numbers, or you’ll get the same problem.