Details
-
Bug
-
Resolution: Done
-
P4: Low
-
5.3.2
-
None
-
8153386397087ce4f5c8997992edf5c1fd38b8db
Description
QVariant doesn't properly convert floats and doubles stored within it to QString.
For example for this float stored within QVariant: 0.035003945
After conversion to QString the string looks like: 0.0350039
After storing string to QVariant and getting float you get: 0.035003901
This is obviously not what is expected and unneeded and unnecessary lose of precision happens.
The Qt implementation internally incorrectly uses: FLT_DIG and DBL_DIG which is only storing number of digits which is always representable by the number (minimum guaranteed).
However this is not maximum guaranteed digits. For C+11 correct solution is to use std::numeric_limits<float>::max_digits10(). If you don't have C+11 support all the time, you need to specify the number manually!
Attachments
Issue Links
- replaces
-
QTBUG-47575 QVariant fp conversion toString different
- Closed
-
QTBUG-47070 [REG 5.4 - 5.5] QtQuick: Decimal value cannot be correctly set to string parameter
- Closed
For Gerrit Dashboard: QTBUG-42574 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
99579,1 | Enhance precision of the FP conversion to strings in QVariant | 5.4 | qt/qtbase | Status: ABANDONED | -1 | 0 |
99815,3 | Enhance precision of the FP conversion to strings in QVariant | dev | qt/qtbase | Status: MERGED | +2 | 0 |