Originally posted by: GuangFeng
You cannot convert 0.2 and 0.01 into IEEE 754 float numbers without losing any precision (round off errors). The way you are doing it:
i=i-0.01
accumulates round off errors over time.
The best way is to use integers. For example, if 0.2 represents 0.2 dollar, try to express it in cents: 20. Or at least you should avoid the accumulation of the round off errors. Try to use something as below at least, although it is still not perfect:
main
{
for (var n=0;n<=20;n++)
{
writeln("i:\t"+((20-n)/100));
}
}
#DecisionOptimization#OPLusingCPLEXOptimizer