Jump to content

Why is my math getting rounded?


benphp

Recommended Posts

var numerator = 186100488800821781.9216;

var denominator = 496;

var quot1 = (numerator / denominator);

document.form.quotient.value = quot1;

 

The result is:

375202598388753.6

 

but the real number (using a calculator) is

375202598388753.59258387096774194

 

It's been rounded off - without even using Math.Round. How do I get the actual number?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/148275-why-is-my-math-getting-rounded/
Share on other sites

As soon as you take any calculus classes you'll realize that absolutely precision is unnecessary, and indeed in many cases impossible. Which number is for instance closest to 0? 1? How about 0.1, 0.01, 0.001, etc.?

 

Even the number you you say is the "real number" is in fact not "real" in the sense you use the word. It's just a matter of how accurate you bother to be.

 

Anyway, check this out: http://www-cs-students.stanford.edu/~tjw/jsbn/. I haven't used it myself, but it came up on a Google search result page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.