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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.