<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QJsonObject::insert use fixed instead of scientific notation when inserting double]]></title><description><![CDATA[<p dir="auto">QT version: 5.15</p>
<p dir="auto">Hello, sorry to bother with this issue I have.</p>
<p dir="auto">I am trying to insert a double variable into a QJsonObject, but I need it to not use special characters like the scientific notation.</p>
<p dir="auto">Most solutions talks about using the std::fixed for streams, which I have issues with translating to my issue.</p>
<p dir="auto">Alternative is to use QString::number, but again I need the object to not be a string of that fashion. If I use QString::number I will get a string instead with quotation marks surrounding the number.</p>
<p dir="auto">Here is an example of my code:</p>
<pre><code>QBytearray jsonDoc;
valueObject = QJsonObject();
double myVariable = 0.0000001;
valueObject.insert("Value", myVariable);
jsonDoc = QJsonDocument(valueObject).toJson();
</code></pre>
<p dir="auto">result is:<br />
{<br />
"Value": 1e-07<br />
}</p>
<p dir="auto">I want:<br />
{<br />
"Value": 0.0000001<br />
}</p>
<p dir="auto">I would even be ok with rounding to 0:<br />
{<br />
"Value": 0.0<br />
}</p>
<p dir="auto">I could round the value so that minimum allowed is 0.001, that way I should avoid the scientific notation. But I'm hoping there is a better solution to my problem?</p>
<p dir="auto">Thanks in advance!</p>
<p dir="auto">Edit: I'm marking this as solved this with Christian Erlichers answer. I believe my issue is somewhere at the other end where I send the data as a bytearray instead of a json to a server which will complain when it finds a scientific notation. This part is outside of QT so I will mark this thread as solved, the answer is that scientific notation should be allowed in JSON structures. I will have to dig deeper into this when I have time.</p>
]]></description><link>https://forum.qt.io/topic/163682/qjsonobject-insert-use-fixed-instead-of-scientific-notation-when-inserting-double</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 05:25:54 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163682.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Nov 2025 07:53:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QJsonObject::insert use fixed instead of scientific notation when inserting double on Mon, 10 Nov 2025 08:40:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dadde">@<bdi>Dadde</bdi></a> said in <a href="/post/833485">QJsonObject::insert use fixed instead of scientific notation when inserting double</a>:</p>
<blockquote>
<p dir="auto">but I need it to not use special characters like the scientific notation.</p>
</blockquote>
<p dir="auto">Then don't use json.<br />
The scientific notation is valid so your parser does not follow the rules.<br />
See <a href="https://www.json.org/json-en.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.json.org/json-en.html</a></p>
]]></description><link>https://forum.qt.io/post/833489</link><guid isPermaLink="true">https://forum.qt.io/post/833489</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 10 Nov 2025 08:40:54 GMT</pubDate></item><item><title><![CDATA[Reply to QJsonObject::insert use fixed instead of scientific notation when inserting double on Mon, 10 Nov 2025 09:16:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dadde">@<bdi>Dadde</bdi></a><br />
As <a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> says.  To be clear, you cannot influence how the JSON output is written (nor how it is read) in the JSON producers/consumers I know.  They only may allow you to influence the irrelevant spacing/indentation/newlines output format, like <a href="https://doc.qt.io/qt-6/qjsondocument.html#JsonFormat-enum" target="_blank" rel="noopener noreferrer nofollow ugc">enum QJsonDocument::JsonFormat</a>.</p>
]]></description><link>https://forum.qt.io/post/833494</link><guid isPermaLink="true">https://forum.qt.io/post/833494</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 10 Nov 2025 09:16:20 GMT</pubDate></item><item><title><![CDATA[Reply to QJsonObject::insert use fixed instead of scientific notation when inserting double on Mon, 10 Nov 2025 08:40:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dadde">@<bdi>Dadde</bdi></a> said in <a href="/post/833485">QJsonObject::insert use fixed instead of scientific notation when inserting double</a>:</p>
<blockquote>
<p dir="auto">but I need it to not use special characters like the scientific notation.</p>
</blockquote>
<p dir="auto">Then don't use json.<br />
The scientific notation is valid so your parser does not follow the rules.<br />
See <a href="https://www.json.org/json-en.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.json.org/json-en.html</a></p>
]]></description><link>https://forum.qt.io/post/833489</link><guid isPermaLink="true">https://forum.qt.io/post/833489</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 10 Nov 2025 08:40:54 GMT</pubDate></item></channel></rss>