The storage requirements for float and double are defined by Java, however
precision during calculation is not. This means that a program that uses
floating point arithmetic can produce different answers on different
systems, with the degree of difference increasing with the number of
calculations a particular value goes through. This is true of floating point
in general, not just in Java.

Justy

----- Original Message -----

> The reason is that floating point numbers only approximate real numbers.
> But this should work if all you want is two decimal places:
>   (*Chris*)
>
> public class Junk {
>
>   public static void main (String[] args) {
>     float d1 = 99.44f;
>     float d2 = 99.40f;
>     float d3 = (float)(Math.rint((d1 - d2) * 100.00) / 100.00);
>     System.out.println(d3);
>   } file://main
>
> }
>
> ----- Original Message -----
> From: "lancelot" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, June 29, 2001 1:41 AM
> Subject: [JSP-INTEREST] Need your help one float and double calc.
>
>
> > Dear all,
> >       Who can tell me why the result is 0.040000916? and why it's not =
> > 0.04, if I want to get 0.04 how could I do? thanks
> >
> > Lancelot
> >
> > D:\test>type testD.java
> > public class testD
> > {
> >   public static void main(String args[])
> >   {
> >     float d1=3D99.44f;
> >     float d2=3D99.40f ;
> >     float d3 =3D d1-d2 ;
> >     System.out.println(d3);
> >   }
> > }
> >
> >
> > D:\test>java testD
> > 0.040000916
> >
> >
>
===========================================================================
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to