Re: Solution for Floating-Point Errors
- From: Randy Webb <HikksNotAtHome@xxxxxxx>
- Date: Mon, 23 Jul 2007 18:08:18 -0400
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/
.
- Follow-Ups:
- Re: Solution for Floating-Point Errors
- From: David Mark
- Re: Solution for Floating-Point Errors
- References:
- Solution for Floating-Point Errors
- From: vunet . us
- Re: Solution for Floating-Point Errors
- From: David Mark
- Solution for Floating-Point Errors
- Prev by Date: Re: writing a toFixed function
- Next by Date: Re: Script for Hiding/Un-Hiding Text On Click
- Previous by thread: Re: Solution for Floating-Point Errors
- Next by thread: Re: Solution for Floating-Point Errors
- Index(es):
Relevant Pages
|