|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I'm using the VERY simple bit of code below to add together two ints, but insted of the right answer 20.8 i get 20.799999999999997. I have no idea whats happening here!! can any give me a hand with this one? Cheers Mark www.freeloader.com code: <html> <head> <title>Number Bug</title> </head> <script language="JavaScript"> <!-- //Just adding two floats together!!!! var tmp = 10.6+10.2; document.write("Adding 10.6 & 10.2 together produces; "+tmp+"<br>"); //Using the function 'nasty' to fix the error tmp = nasty(tmp); document.write("Using a nasty function to fix the error produces; "+tmp+"<br>"); document.close(); function nasty(fixedInt){ fixedInt = Math.round(fixedInt * 10); return fixedInt /= 10; } // --> </script> <body> </body> </html> |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > float weirdness |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|