converting from float or double to QString results in output being 0
-
@Dean21
Glad it's working for you now. That's the steps I would have taken to get it working.@Kent-Dorfman said earlier
I question whether removing non-numeric char at end of QSTring is necessary for the numeric conversion problem since all the conversion code I'm familiar with scans digits until it finds an char that can't be part of the number, and then returns everything up to that point.
But, for whatever reason, conversions to numeric from
QString
state:Warning: The
QString
content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.So that's how they do it --- all characters in the string must be valid. You could use:
bool ok; double val = msg_as_Qstring.toDouble(&ok); if (!ok) qDebug() << "Conversion failed!";
-
@JonB said in converting from float or double to QString results in output being 0:
Warning: The QString content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.
In which case RTFM is the rule of the day! but I'm lazy.