The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000

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:

adding 2 float number did not get expected result

Posted by Albert on November 26, 2000 at 8:33 AM

Hello,

Adding 2 float numbers, 20.4 and 40.8 gives me 61.199997,
instead of 61.2.

Can anyone reproduce the result with the source below ?

---------------
public class test {

public static void main( String[] para ) {

float a = (float) 20.4;
float b = (float) 40.8;

float c = a+b;
System.out.println( "a :" + a );
System.out.println( "b :" + b );
System.out.println( "c =a+b :" + c );
}
}

----my output :

a :20.4
b :40.8
c =a+b :61.199997




Replies:

Sponsored Links



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