[Qt-interest] string to float

Paul Floyd paulf at free.fr
Wed Jan 27 14:38:28 CET 2010


Quoting yanqzhi at gmail.com:
> hi,
>
> When a string converts to a float, the float returned does't exactly match
> the string;
>
>  QString str("57.130");
>  float a = str.toFloat();
>
> the float is 57.130001.

Welcome to the world of floating point, and in this case its finite precision.

Have a read of this.

http://docs.sun.com/source/806-3568/ncg_goldberg.html

A+
Paul
-- 
Paul Floyd   http://paulf.free.fr



More information about the Qt-interest-old mailing list