🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18226

Re: double trouble: 8.3 + .4 = 8.70000000000001???!?

#18226
From: Jennifer Merkel
Date: Mon, 20 Jul 1998 00:00
29 lines
1522 bytes
There is a BigDecimal class in java.math.  Maybe this could help you, I use
it to represent money.

Jen

Alex Humphreys wrote:

> I'm trying to add a group of doubles (for column totals in my grid) and
> I'm getting STRANGE data with decimal points.  Seemingly randomly, it
> will throw on an extra 15 or so digits.  Now, I've read about Floating
> Point problems with this, so I'm assuming that this is an off-shoot of
> that problem.
>
> Is there a way around this problem?
>
> I'm trying to format the solution using DoubleFormatter, but can't get
> the syntax right.  I'm trying:
>
>     DoubleFormatter double_f = new DoubleFormatter(7);
>     double_f.setPattern("###.{##}");
>     Variant temp_v = new Variant();
>     double_f.setFromDouble(temp_v, 7, my_dataRow.getDouble("my_col"));
>     my_col.setText(temp_v.toString());
>
> And of course this doesn't do a darn thing.  What am I missing?
>
> Thanks.
>
> Alex
Technical Details
Message-ID: <35B33F31.936CE2D1@EdmundsAssoc.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35AFA52B.1DF12AA4@sema4.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,bd15110277a7fe10
X-Google-Attributes: gidf74b3,public
From: Jennifer Merkel <JenniferM@EdmundsAssoc.com>
Subject: Re: double trouble:  8.3 + .4 = 8.70000000000001???!?
Date: 1998/07/20
Message-ID: <35B33F31.936CE2D1@EdmundsAssoc.com>
X-Deja-AN: 373149743
Content-Transfer-Encoding: 7bit
References: <35AFA52B.1DF12AA4@sema4.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language