Article View: borland.public.jbuilder.java.api
Article #2536Re: Simple problem for float calculation
From: Eric Hodges
Date: Tue, 17 Oct 2000 00:00
Date: Tue, 17 Oct 2000 00:00
24 lines
1131 bytes
1131 bytes
Use doubles instead of floats and you'll get 27.3. That won't always work because of the way floating point numbers are handled (this isn't just a Java issue, the same thing happens in C and C++.) To use fixed decimal point math, use ints like this: int a = 271; int b = 2; int c = a + b; double d = c /100d; "eLe" <petruschan@realink.com.hk> wrote in message 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 ! > >
Technical Details
Message-ID:
<39ec6524_2@dnews>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: "Eric Hodges" <harmony2@swbell.net> Subject: Re: Simple problem for float calculation Date: 2000/10/17 Message-ID: <39ec6524_2@dnews> X-Deja-AN: 682484925 References: <39ec3576_2@dnews> X-Trace: 17 Oct 2000 07:41:40 -0800, 216.62.142.31 X-MSMail-Priority: Normal X-Priority: 3 Newsgroups: borland.public.jbuilder.java.api X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400