HighDots Forums  

Re: Math Problem

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Math Problem in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Randy Webb
 
Posts: n/a

Default Re: Math Problem - 10-05-2005 , 12:37 PM






McKirahan said the following on 10/5/2005 7:44 AM:

Quote:
How do I add floating point numbers accurately?

The following adds the 4 numbers
46.57, 45.00, 45.00, and 54.83 to give
191.39999999999998 instead of 191.40.
You convert them to whole numbers, do your math, and then use string
manipulation to put the decimal back where you want it along with
leading and/or trailing zeroes.

Quote:
P.S. This FAQ doesn't help:
http://jibbering.com/faq/#FAQ4
4.7 Why does 5 * 1.015 != 5.075 or 0.05+0.01 != 0.06?
4.7 along with 4.6 do answer your question, they just aren't very well
worded and/or explained enough to make sense to anybody that doesn't
understand it to start with.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.