Thanx & Regards,
Hem
Numbers like 0.07 cannot be represented exactly in floating point binary,
the internal javascript conversion, so they are aproximated.
It is normal behavour. If you do not like it you should round.
<script>
a=.07*100
document.write(a+" = normal behavour<br>")
a=Math.floor(a+0.5)
document.write(a+" = rounded<br>")
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
A decimal class for Java
http://www2.hursley.ibm.com/decimalj/
I know Mike personally and for seveal years he has been working with
both hardware & software developers to try to get decimal arithmetic
as the standard. Several languages (Rexx included) already use
decimal arithmetic.
Lee
Long, long ago (1982?), Bill Gates (himself?) wrote "Central Data Basic"
for the Signetics/Philips 2650 microprocessor.
This BASIC's arithmetic was compleatly decimal.
It was a joy for financial programming. I made a special version changing
the decimal point with a decimal comma by changing one bite in the
executable.
>onload = "alert(.07*100)"
>Numbers 7, 14, 28, 29, 55,
>56,57,58,109,110,111,,112,113,114,115,116.... donot return
>as whole numbers while others do. I couldnot reason this
>behaviour. Could anyone please help me in this.
Read the c.l.j FAQ, and the links therefrom; and my site.
Numbers are held as IEEE Doubles, in binary; and so most decimal
fractions are inexact.
--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MSIE 4 ©
<URL:http://www.jibbering.com/faq/> FAQ for comp.lang.javascript by Jim Ley.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Regards,
Hemkiran
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!