How to preserve zeros at end of doubles in QJsonDocument?

75 Views Asked by At

I'm reading, parsing and writing back a JSON file in a QT project. Part of the requirements is that all entry's should be the same written out as declared in the source file.

One of the entries looks somewhat like this:

"SomeVal": 1.23141241242140

When I read the JSON object, the last zero (0) is removed. That does make sense, since it is not needed for normal use cases. But, since I need to preserve the whole correct number, including that last zero, this is incorrect for me. Any clue on how I can bypass this problem?

The code that reads the JSON file:

QString rawJson = "";
QFile jsonFile(filePath);
if(jsonFile.exists())
{
    jsonFile.open(QFile::ReadOnly|QFile::Text);
    rawJson = jsonFile.readAll();
    jsonFile.close();
}
else
{
    return false;
}

QJsonParseError json_parse_error;
QJsonDocument json_doc = QJsonDocument::fromJson(rawJson.toUtf8(), &json_parse_error);
if(json_parse_error.error != QJsonParseError::NoError)
{
    emit SignalMessageCritical(QString(json_parse_error.errorString()));
    return false;
}
this->jsonTestFile = json_doc.object();
0

There are 0 best solutions below