🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#18300
From: Alex Humphreys
Date: Fri, 17 Jul 1998 00:00
22 lines
1294 bytes
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: <35AFA52B.1DF12AA4@sema4.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

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