W3C home > Mailing lists > Public > site-comments@w3.org > May 2011

JavaScript Bug?

From: Khurram Adeeb Noorani <khurramnoorani@gmail.com>
Date: Wed, 04 May 2011 21:25:29 +0000
Message-Id: <BANLkTi=kxeynVrOriPZADAqvEMOy7s5YVA@mail.gmail.com>
To: site-comments@w3.org
Hello!

I am writing you for the very first time in my life. Today I came across something really weired in JavaScript, I would call it a bug and it's my request that please have a look at it.

Please run the following script in your browser and you will see what I mean.

<script type="text/javascript">
num=0.14;
num+=0.01;
alert(num);
</script>

Please don't say that rounding up will solve the problem. I know rounding up will solve the problem but the point is that there is something wrong. And it took hours to debug it because I really had no idea that there could have been such type of mistake/bug/issue in JavaScript. I was doing debugging somewhere else and the root cause was somewhere else. And the most interesting thing is that if you have num=0.13 and you add 0.01 to it, it will work fine. Problem occurs ONLY when you have num=0.14 and you add 0.01 to it.

It tested the above code on different machines (both Windows and Mac) and different browsers (Chrome, Firefox and Safari).

I've really no idea where to write and who to address therefore I'm sending an email to this address, kindly forward it to the concerned authorities.

-- 
regards,
K.A.Noorani
Received on Thursday, 5 May 2011 05:33:21 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 24 October 2012 16:21:33 GMT