-
need solution: 30.01 + 30.03= 60.0400000000000006 (5 messages)
- Posted by: harish prabhu
- Posted on: June 13 2006 06:16 EDT
hi all, pls advice any solution to the following overflow problem while adding 2 numbers in javascript. 30.01 + 30.03 = 60.0400000000000006 whereas 30.01 + 30.04= 60.05 thanksThreaded Messages (5)
- Re: need solution: 30.01 + 30.03= 60.0400000000000006 by Stefan Arentz on June 14 2006 15:27 EDT
- Re: need solution: 30.01 + 30.03= 60.0400000000000006 by Mithat Karaoglu on June 15 2006 10:10 EDT
- Re: need solution: 30.01 + 30.03= 60.0400000000000006 by Kamati Pura on June 16 2006 09:36 EDT
- Re: need solution: 30.01 + 30.03= 60.0400000000000006 by Fernando del Rio on June 21 2006 11:07 EDT
- Re: need solution: 30.01 + 30.03= 60.0400000000000006 by Sanket Raut on June 22 2006 02:00 EDT
-
Re: need solution: 30.01 + 30.03= 60.0400000000000006[ Go to top ]
- Posted by: Stefan Arentz
- Posted on: June 14 2006 15:27 EDT
- in response to harish prabhu
In Java you would solve this by using a double instead of a float. In JavaScript you cannot make that choice so it is probably easiest to use cent values in your scripts and divide by 100 to present values. S. -
Re: need solution: 30.01 + 30.03= 60.0400000000000006[ Go to top ]
- Posted by: Mithat Karaoglu
- Posted on: June 15 2006 10:10 EDT
- in response to harish prabhu
If you are dealing with kind of accounting stuff, you should use BigDecimal class. Mithat -
Re: need solution: 30.01 + 30.03= 60.0400000000000006[ Go to top ]
- Posted by: Kamati Pura
- Posted on: June 16 2006 09:36 EDT
- in response to harish prabhu
Any particular reason why a javascript error is posted in the ejb design forum? -
Re: need solution: 30.01 + 30.03= 60.0400000000000006[ Go to top ]
- Posted by: Fernando del Rio
- Posted on: June 21 2006 11:07 EDT
- in response to harish prabhu
You can always use something like this: function formatNumber(number) { return Math.round (number *100) /100; } -
Re: need solution: 30.01 + 30.03= 60.0400000000000006[ Go to top ]
- Posted by: Sanket Raut
- Posted on: June 22 2006 02:00 EDT
- in response to harish prabhu
Its mainly because of inability to represent 0.1 exactly in binary. The problem is not with java,same result will be observed in c,c++,basic,pascal,etc..... Regards, Sanket