Jump to content

Multiplication Question


rtroxler

Recommended Posts

I don't understand it well enough to explain to other people other than to say that computers aren't really able to represent floating point numbers very well. If all you are doing is multiplying by 0.01, you might consider dividing by 100 instead:

<html><body><script>// outputs 38758.700000000004document.write("3875870 * .01 = " + (3875870 * .01) + "<br />");// outputs 38758.7document.write("3875870 / 100 = " + (3875870 / 100) + "<br />");</script></body></html>

Link to comment
Share on other sites

Dividing by zero is what I did to resolve but it just bothered me that a basic calculation didn't return what I expected. I am fairly new to JS and I have never seen this any place else.Had a addition go funky on me too (3698850.26 + 883.34) came out as 373609.60000000003. Is there a better method or variable type to use for calculations? For the addition error, I stripped decimal position out, added the two whole numbers then divided by 100 to replace the decimal point. Sure a lot of work just to do basic math.Thanks for the input all.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...