songvan
songvan

Reputation: 379

correct input value with toFloat() in Qt

I want to change text into float number for calculation in Qt

float test = ui.tableWidget->item(0, 1)->text().replace(",", ".", Qt::CaseSensitive).toFloat();

when I type 2.86, actually I see test = 2.85999990 in debug. How can I receive correctly what i typed ?

I can use this for showing

qDebug() << QString::number( test, 'f', 2 );

But I want a value for calculation, not for showing.

Upvotes: 1

Views: 848

Answers (1)

maxik
maxik

Reputation: 1123

As @hauron already said this is format specific but normal behaviour. You might want to take a read on this.

Additionally you might also take a look at another answer here. Using some additional library may work for you, if applicable.

Upvotes: 1

Related Questions