QJsonDocument::toJson() generates extra large text. Is there way to fix it? QJsonDocument::toJson() generates extra large text. Is there way to fix it? json json

QJsonDocument::toJson() generates extra large text. Is there way to fix it?


On OS X I tried the following: -

QVariant d(0.5);QJsonValue val = QJsonValue::fromVariant(d);qDebug() << val.toDouble();

This prints out 0.5, as expected.

However, I think the problem is due to floating point precision. QJSonDocument is representing the number as accurately as possible, but does not have a function to limit the number of decimal places represented, as is present in QString.

Though not ideal, if your really want 0.5 represented this way, you can write a string value instead of the double.