if your value a = 0.0009999999, you can do the following,
if ( fabs( a - 0.001) < 1.e-7 )
{
a = 0.001;
}
another way
if ( fabs( a * 1000.0 - 1.0 ) < 1.e-5 )
{
a = 0.001;
}
Normally floating conversion error can not be avoided. Little thing. But you need to be aware of.
引用楼主10点睡觉于2009-11-13 22:39发表的 求救啊,qt中关于浮点类型的处理。。。 :
我想从利用字符串类的类型转换功能把字符串”0.001“,转换成浮点类型的0.001,利用toFloat()成员函数转换后精度不够啊,离0.001很近,但不是0.001,有没有好的方法,转换成非常精确的值??万分感谢!!
[ 此帖被steinlee在2009-11-14 01:38重新编辑 ]