diff options
| author | Liang Qi <liang.qi@qt.io> | 2017-03-27 08:43:19 +0000 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-03-27 09:21:47 +0000 |
| commit | d5df0e99490098a8ed5ccdb29a82f796d41044e3 (patch) | |
| tree | c540bf33502b2aa4f0c0ae8a28a8fc22a4a78ac6 /src/corelib/json/qjsonwriter.cpp | |
| parent | 1e7795ef604fe22895b8ec5c2278fea4217f2c07 (diff) | |
| parent | 7702fe86029c771e641a918baa221b9737c0f18e (diff) | |
Merge "Merge remote-tracking branch 'origin/5.8' into 5.9" into refs/staging/5.9
Diffstat (limited to 'src/corelib/json/qjsonwriter.cpp')
| -rw-r--r-- | src/corelib/json/qjsonwriter.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/json/qjsonwriter.cpp b/src/corelib/json/qjsonwriter.cpp index b1544c749de..12ce20ef09a 100644 --- a/src/corelib/json/qjsonwriter.cpp +++ b/src/corelib/json/qjsonwriter.cpp @@ -38,6 +38,7 @@ ** ****************************************************************************/ +#include <cmath> #include <qlocale.h> #include "qjsonwriter_p.h" #include "qjson_p.h" @@ -129,10 +130,12 @@ static void valueToJson(const QJsonPrivate::Base *b, const QJsonPrivate::Value & break; case QJsonValue::Double: { const double d = v.toDouble(b); - if (qIsFinite(d)) // +2 to format to ensure the expected precision - json += QByteArray::number(d, 'g', QLocale::FloatingPointShortest); - else + if (qIsFinite(d)) { // +2 to format to ensure the expected precision + const double abs = std::abs(d); + json += QByteArray::number(d, abs == static_cast<quint64>(abs) ? 'f' : 'g', QLocale::FloatingPointShortest); + } else { json += "null"; // +INF || -INF || NaN (see RFC4627#section2.4) + } break; } case QJsonValue::String: |
