benphp Posted March 6, 2009 Share Posted March 6, 2009 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? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 http://en.wikipedia.org/wiki/Floating_point Quote Link to comment Share on other sites More sharing options...
benphp Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks. Do you know how to fix it? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 That's the precision limit for 32 bit (single) floating point number. Not sure if you can have any more precision in JavaScript. [edit] 32bits is single precision of course. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 6, 2009 Share Posted March 6, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.