<?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 QJsonValue(double) looses precision]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I have a double value which i want to bring into a QJsonObject. But on inserting the QJsonValue into the QJsonObject the precision of the value changed. But why</p>
<p dir="auto">@<br />
double x = 23.2;<br />
QJsonObject obj;<br />
QJsonValue v = QJsonValue(x);<br />
obj.insert("value",v);</p>
<pre><code>qDebug() &lt;&lt; x;
qDebug() &lt;&lt; v;
qDebug() &lt;&lt; obj;
</code></pre>
<p dir="auto">@</p>
<p dir="auto">returns:</p>
<p dir="auto"><em>23.2</em><br />
<em>QJsonValue(double, 23.2)</em><br />
<em>QJsonObject({"value": 23.199999999999999})</em></p>
<p dir="auto">What's going wrong here. Can anybody help me pls?</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.qt.io/topic/37969/qjsonobject-insert-qjsonvalue-double-looses-precision</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 02:39:40 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/37969.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Feb 2014 08:55:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QJsonObject insert QJsonValue(double) looses precision on Sat, 22 Feb 2014 04:46:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi, and welcome to the Qt Dev Net!</p>
<p dir="auto">There are two things you need to be aware of:</p>
<h1>Your loss of precision occured when you assigned 23.2 to <em>x</em>. A</h1>
<p dir="auto"><em>double</em>, as defined by the "IEEE floating point standard":<a href="http://en.wikipedia.org/wiki/IEEE_floating_point" target="_blank" rel="noopener noreferrer nofollow ugc">http://en.wikipedia.org/wiki/IEEE_floating_point</a>, cannot store 23.2 precisely.</p>
<h1>The different outputs you saw is due to "roundings" that qDebug() did before displaying the text. All 3 values are actually the same.</h1>
<p dir="auto">To check yourself, do this:<br />
@<br />
qDebug() &lt;&lt; obj;<br />
qDebug() &lt;&lt; obj.value("value");<br />
qDebug() &lt;&lt; obj.value("value").toDouble();<br />
@</p>
]]></description><link>https://forum.qt.io/post/215813</link><guid isPermaLink="true">https://forum.qt.io/post/215813</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Sat, 22 Feb 2014 04:46:22 GMT</pubDate></item></channel></rss>