Problem with Number(). parseFloat(), eval()
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Erhan_Erdem
Posted On:   Monday, March 1, 2004 05:24 PM

Does anybody have any idea why this code wouldn't give me the correct value for the variable "test":

var test = Number(5) + Number(12.4) + Number(0) + Number(0.4) + Number(0);

I expect the result to be 17.8, instead I get 17.799999999999997

If I use eval() or parseFloat() instead of Number() the result is the same...

I don't want to round up the number. I'm really curious why the test code above wouldn't give me the correct result, and what I should do to get the correct result.

Thanks!!!

Re: Problem with Number(). parseFloat(), eval()

Posted By:   Anjan_Bacchu  
Posted On:   Monday, March 1, 2004 08:41 PM

Here's another -- with detailed


http://www2.hursley.ibm.com/decimal/decifaq1.html



BR,

~A

Re: Problem with Number(). parseFloat(), eval()

Posted By:   Anjan_Bacchu  
Posted On:   Monday, March 1, 2004 08:39 PM

Hi There,



Here's a very good article on this subject. http://www-106.ibm.com/developerworks/java/library/j-jtp0114/



BR,

~A
About | Sitemap | Contact