This post originated from an RSS feed registered with .NET Buzz
by Jason Nadal.
Original Post: Javascript Bad Math
Feed Title: Jason Nadal
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/jnadal/Rss.aspx
Feed Description: Restless C#ding
I really wish someone could explain to me how, in javascript, the following calculation happens:
0.2320 * 100 = 23.20000000000003
Check out the following script, which I only managed to fix by setting the precision of the offending result to 4 significant digits. The glitch can be seen with the following script:
<html> <body> <script language="javascript"> var x = Number('0.2320'); alert(x); var y = x*100; alert(y); </script> </body> </html>