Re: Solution for Floating-Point Errors



David Mark said the following on 7/23/2007 5:28 PM:
On Jul 23, 4:35 pm, vunet...@xxxxxxxxx wrote:
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.00831109999999999999
can I avoid this by a better method than comparing 2 number length
after decimal point and using toFixed() to match shorter number with
another one?
Thanks.

Yes. To make it simpler, multiply each by 1000000 before adding:

8310 + 1 = 8311


0.00831 + 0.000001 != 8311

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
.



Relevant Pages

  • Re: Solution for Floating-Point Errors
    ... David Mark said: ... can I avoid this by a better method than comparing 2 number length ... after decimal point and using toFixedto match shorter number with ...
    (comp.lang.javascript)
  • Re: Solution for Floating-Point Errors
    ... David Mark said the following on 7/23/2007 7:24 PM: ... can I avoid this by a better method than comparing 2 number length ... Multiply both of your decimals by 100000, add them, then divide the answer by 100000 to get the decimal back. ...
    (comp.lang.javascript)
  • Re: Solution for Floating-Point Errors
    ... David Mark said: ... can I avoid this by a better method than comparing 2 number length ... after decimal point and using toFixedto match shorter number with ...
    (comp.lang.javascript)
  • Re: How do you compare bookmarks in DAO recordsets?
    ... but Van Dinh's last post made it clear how I could avoid ... comparing bookmarks and compare primary key fields instead. ... >>I posted my problem on another Access forum and got a response providing a ...
    (microsoft.public.access.formscoding)
  • Re: "Hustle"
    ... in article 3dellis-664015.07061131032006@xxxxxxxxxxxxxxxxx, Richard Ellis at ... Just be sure to catch the late night ones, and avoid the earlier episodes - ... I'm watching both shows - and comparing them isn't really fair, ...
    (rec.arts.tv)