🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1289

Re: help with Double.toString(double)

#1289
From: Douglas Moffitt
Date: Mon, 25 Mar 2002 19:29
43 lines
2857 bytes
On Thu, 18 Oct 2001 14:03:32 +0100, "Ant�nio Ferreira"
<antonio.ferreira@artesis.co.pt> wrote:

>Greetings,
>
>  I would like to make a correction: in my text I wrote
>formatedNumber=0.99999... and it should be 0.09999...
>  With nothing else to say I thank all your attention
>
>             Ant�nio Jos� Ferreira
>
>"Ant�nio Ferreira" <antonio.ferreira@artesis.co.pt> wrote in message
>news:3bceb76f_2@dnews...
>> Hi,
>>
>>   I am using the following code:
>>
>>     formatedNumber = Double.toString(number);
>>
>>   where formatedNumber is a string and number is a double. When number is,
>> for example, 0.1 the conversion isn't done correctly
>> (formatedNumber="0.999999999999999980"). If number is 80.0 the conversion
>is
>> done correctly. By the way, I am using java 2 and Jbuilder 3. Can anyone
>> help me?
>>   I appreciate all your help. Thanks,
>>
>>                                                    Ant�nio Jos� Ferreira
Antonio,

It is working perfectly.

You are forgetting that all decimal fractions except those that are
exact powers of 2 are approximations when represented in binary, as in
a digital computer.  Java conversions do not round up as some other
languages do, so 0.1 ==> 0.09999.....

Integers, such as 80, are represented exactly.

If you need the answer to be exactly 0.1, you will have to use another
method, of which there are several.

Doug
Technical Details
Message-ID: <n0uu9uoif4g9nsibgg296i979c2bjikil7@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.gamma.ru!Gamma.RU!colt.net!newspeer.clara.net!news.clara.net!news-hub.cableinet.net!blueyonder!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!bin8.nnrp.aus1.giganews.com.POSTED!not-for-mail
References: <3bceb76f_2@dnews> <3bced32d_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1089d0,596565ba2e6ec3ff
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-03-25 11:26:23 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.gamma.ru!Gamma.RU!colt.net!newspeer.clara.net!news.clara.net!news-hub.cableinet.net!blueyonder!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!bin8.nnrp.aus1.giganews.com.POSTED!not-for-mail
From: Douglas Moffitt <dougmoffitt@drum-fife.com>
Newsgroups: borland.public.jbuilder.java.api
Subject: Re: help with Double.toString(double)
Reply-To: dougmoffitt@drum-fife.com
Message-ID: <n0uu9uoif4g9nsibgg296i979c2bjikil7@4ax.com>
References: <3bceb76f_2@dnews> <3bced32d_1@dnews>
X-Newsreader: Forte Agent 1.9/32.560
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 43
NNTP-Posting-Date: Mon, 25 Mar 2002 13:29:27 CST
Organization: Giganews.Com - Premium News Outsourcing
X-Trace: sv3-THrNxGdWgXQrkfwSFV+9kIgh1MaAhWt7jtW4WoZU+ZSPKIW8HxJ0Dh5yR5w8kifgR78LWSCrbqEVrNw!FYKAYQ/3M/Ec3Ln8EsJ9iAXqFQ9bK/LfTx3KzfKIkZ39qYi90W3mUv00i2HK8ruFrw9b
X-Complaints-To: abuse@comcast.com
X-DMCA-Complaints-To: abuse@comcast.com
X-Abuse-Info: Please be sure to forward a copy of ALL headers
X-Abuse-Info: Otherwise we will be unable to process your complaint properly
Date: Mon, 25 Mar 2002 19:29:27 GMT