View Full Version : qstring k="100.1",how to convert to int = 100 ?
lanmanck
8th September 2009, 15:49
when i invoke toInt(), it return 0.
now i first use atoi(), and then QString::number();
but, it seems too much procedure???
how can i do that only using QString's method ?
thanks.
cydside
8th September 2009, 16:03
Try
QString::toDouble();
and then take the integer part!
:D
hkvm
8th September 2009, 16:29
Alternatively, you can strip the decimals away from the string:
QString str("100.1");
int number = str.left(str.indexOf('.')).toInt(); // == 100
Works even if there isn't a decimal part, because str.left(-1) returns the whole string.
faldzip
8th September 2009, 18:08
for me this should be enough:
QString str("100.1");
int x = str.toDouble();
lanmanck
9th September 2009, 04:15
i appreciate all the replyies ;)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.