可能重复:
将小数位移动到双精度
代码 :
public class Teste {
public static void main(String[] args) {
System.out.println("Exponent loop:");
for(int i=1; i<10; ++i)
System.out.println(Math.pow(0.1, i));
System.out.println("\nMultiplication loop:");
double a = 1;
for(int i=1; i<10; ++i){
a *= 0.1;
System.out.println(a);
}
}
}
输出:
指数循环:
0.1
0.010000000000000002
0.0010000000000000002
1.0000000000000002E-4
1.0000000000000003E-5
1.0000000000000004E-6
1.0000000000000004E-7
1.0000000000000004E-8
1.0000000000000005E-9
乘法循环:
0.1
0.010000000000000002
0.0010000000000000002
1.0000000000000003E-4
1.0000000000000004E-5
1.0000000000000004E-6
1.0000000000000005E-7
1.0000000000000005E-8
1.0000000000000005E-9