The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Help me please!

Posted by student on November 28, 2001 at 11:59 AM

This is piece of code:

public static void main(String[] args) {
double rate;
rate = 0.05;
while (rate <= 0.1)
{
System.out.println("rate = "+ rate);
double a = 0.01;
rate += a;
}
}
And this is an output:

rate = 0.05
rate = 0.060000000000000005
rate = 0.07
rate = 0.08
rate = 0.09
rate = 0.09999999999999999

I would expect the result would be different. Does anyone know why it is not what I expected and how would I fix it?
Thanks.





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us