信息交流、传播、提炼

nice to meet you

博客园 首页 新随笔 联系 订阅 管理

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;

posted on 2008-03-25 19:11  seeyou  阅读(1147)  评论(0)    收藏  举报