1

I found a interesting thing when i try to converting QString to float by using toFloat() function.

Here is the code:

QString src = "500.05";
int x = src.toFloat() * 100;
float y = src.toFloat() * 100;
int z = (int)(500.05 * 100);

qDebug() << x;
qDebug() << y;
qDebug() << z;

And here is the output:

50004 //x
50005 //y
50005 //z

My question is why i got x is 50004. So is this a Bug or i did something incorrect.

JustWe
  • 4,250
  • 3
  • 39
  • 90

0 Answers0