it is impossible for some numbers to be represented exactly in IEEE format, which is what javascript uses for floating point numbers. This is not a "bug" perse, but rather a limitation of representing floating point numbers in a finite set of bits. These sorts of floating-point roundoff errors are present in all programming languages as far as i'm aware (?) but i could be wrong.
you might want to use a round function for presentation of your numbers.
var tt=10
var pprice=6.64
var multi = pprice*tt
var value = multi.toFixed(2)
alert(value)
or just
var tt=10
var pprice=6.64
var multi = pprice*tt
alert(multi.toFixed(2))
BTW, my reference say that 'toFixed' converts a number to a a string so beware it's a string.
To keep make it a number again you can do something like:
var value = parseFloat(multi.toFixed(2))
But in that case the argument in 'toFixed(argument)' determines the number of digits after the decimal point and rounds the trailing digits as appropiate.
Hope this helps,
Erik
<-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.