|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
There seems to be a bug in Javascript using simple multiplication.
If you times 286.40 times 100 you should get 286.40 but it gives you back 286.39.9999999996. To prove I am not crazy I have a short script that does just that. www.myus.com/test.html I did a search on the net and can not find any info on this. I know how to get around it I just want to know why such a simple error has not yet been fixed within javascipt. Or am I clueless and this is not a bug? Im can't belive I am the first to notice this. It only seems to do it with this number but there might be others. Here is the test code that is at the page above. <script type="text/javascript"> function test() { var tmp = 0; tmp = (286.40*100); alert (tmp); } // end test function </script> <a href="#" onClick="test();">test</a> 286.40 |
|
#2
|
||||
|
||||
|
Check out http://www.merlyn.demon.co.uk/pas-real.htm#Float. This doesn't give an exact answer to your specific question, but it suggests that floating point numbers can be tricky. Just because something looks to us like it'd be a round number apparently doesn't mean it is in floating point arithmetic.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
dhouston Thanks,
I am glad I am not going crazy. Eddie |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Bug with multiplication in JavaScript 286.40 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|