Article View: borland.public.jbuilder.java.language
Article #8546Re: double division rounding error
From: Joi Ellis [TeamB]
Date: Tue, 13 Mar 2001 15:10
Date: Tue, 13 Mar 2001 15:10
26 lines
1919 bytes
1919 bytes
Ron Reynolds <ron@ronreynolds.com> wrote: > using doubles is a requirement, but most values we work with are > currency values (or stock prices) and the docs indicate that > float is good for up to 6 significant decimal digits, so i think > i'm safe on the precision loss. It is never safe to use floating point numbers for currency when you have to track the value correct to the penny. When expressed in binary, basic currency components like 1/10 and 1/100 are irrational numbers! Just as the value of pi is irrational in decimal, 1/10 is irrational in binary. You will always have roundoff problems if you use a floating-point number. > i'd really like to know how would one of you guys would have > solved this same problem. Use bigdecimal or integers, and manipulate the values in pennies, not dollars. Convert to dollars only when displaying the balance in a UI. -- Joi Ellis (TeamB) No direct email, please. For best results, post on news server newsgroups.borland.com! Newsgroup Info: http://www.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<98ld92$qu414@bornews.inprise.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!netnews.com!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mailReferences:
<3aad499f$1_2@dnews> <usnkioyup.fsf@sds.no> <3aae2be1$1_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,1db527391e14d00c
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-13 07:16:12 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!netnews.com!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mail
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: double division rounding error
Date: 13 Mar 2001 15:10:26 GMT
Organization: Another Netscape Collabra Server User
Lines: 26
Message-ID: <98ld92$qu414@bornews.inprise.com>
References: <3aad499f$1_2@dnews> <usnkioyup.fsf@sds.no> <3aae2be1$1_2@dnews>
NNTP-Posting-Host: linux.aravox.com
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.16-3 (i686))