Article View: borland.public.jbuilder.java.api
Article #2535Re: Simple problem for float calculation
From: Johan Forsberg
Date: Tue, 17 Oct 2000 00:00
Date: Tue, 17 Oct 2000 00:00
16 lines
1084 bytes
1084 bytes
"eLe" <petruschan@realink.com.hk> skrev i meddelandet news:39ec3576_2@dnews... > I have Java program simple as : > > float a = 27.1 > float b = 0.2 > float c = a + b > c = 27.300001 > > I want the ans is c = 27.3 is not 27.300001 > > How to solve this problem ? thank you ! 1) Get a processor with an infinite number of bits in the float registers :-) 2) Use java.text.DecimalFormat to print c with ie. 2 decimals.
Technical Details
Message-ID:
<8shkdr$i6r21@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39ec3576_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,9bcc96b038465cb3 X-Google-Attributes: gid1089d0,public From: "Johan Forsberg" <jfo@SPAMfinansforbundet.SPAMse> Subject: Re: Simple problem for float calculation Date: 2000/10/17 Message-ID: <8shkdr$i6r21@bornews.borland.com> X-Deja-AN: 682463641 Content-Transfer-Encoding: 7bit References: <39ec3576_2@dnews> Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal X-Priority: 3 Content-Type: text/plain; charset="Windows-1252" Mime-Version: 1.0 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Newsgroups: borland.public.jbuilder.java.api