S
Stefan Ram
I teach some properties of the data type »double«:
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( 0.1 + 0.1 + 0.1 == 0.3 );
java.lang.System.out.println( 1.1 * 1.1 == 1.21 ); }}
false
false
. I also teach that beginners should not use the data type
»float«, because it will only cause trouble.
But now a student came up with this:
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( 0.1f + 0.1f + 0.1f == 0.3f );
java.lang.System.out.println( 1.1f * 1.1f == 1.21f ); }}
true
true
. So, now it looks as if double just does the wrong thing
and as if float just does the right thing.
How does one deal with this, when explaining, when to use
»float« and when to use »double«?
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( 0.1 + 0.1 + 0.1 == 0.3 );
java.lang.System.out.println( 1.1 * 1.1 == 1.21 ); }}
false
false
. I also teach that beginners should not use the data type
»float«, because it will only cause trouble.
But now a student came up with this:
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( 0.1f + 0.1f + 0.1f == 0.3f );
java.lang.System.out.println( 1.1f * 1.1f == 1.21f ); }}
true
true
. So, now it looks as if double just does the wrong thing
and as if float just does the right thing.
How does one deal with this, when explaining, when to use
»float« and when to use »double«?