I have a problem concerned with losing of precision
my task is to print numbers as strings
int exponent = ...
int[] Mantissas = { 1, 2, 5 };
double dataStep = java.lang.Math.pow(10.0, exponent) * Mantissas[mantissaIndex];
...
for (int i = 0; i < NSteps; i++)
steps[i] = firstStep + i * dataStep;
draw(steps);
for example, 0.2*7=1.4000000000000001; 0.0000014/10=1.3999999999999998E-7
how to figure out this problem?
UPD: The main problem is string output formating. i don't bother about losting of about 0.00000001 value.
Now I solved it as String.format("%f", value),
but I think it's not good approach
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…