1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| double a = 230.13075;
double b = 178.17765;
double c = a - b;
// Affichage par défaut (avec les approximations) :
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println();
// On utilise un formatter avec un maximum de 8 décimales :
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
nf.setMaximumFractionDigits(8);
// Affichage OK (sans les approximations) :
System.out.println( nf.format(a) );
System.out.println( nf.format(b) );
System.out.println( nf.format(c) ); |