Today,I read some source code of somebody's program,and try run it,when I send some test data into it,the output has a problem,trace and debug it,find that the program use double type incorrectly,and cause the precision error,so if you do not sure of using double type,you'd use decimal type.
the original code:
double factor = ...
double qty = ...
double amt = ...
if(qty*factor == amt) /*if qty=360000.0 and factor=0.14,the qty*factor=50400.0000007
{
...
}
if change double to decimal,you can find 360000.0*0.14=50400 currectly
ps:0.00 == 0.0 is true;
浙公网安备 33010602011771号