<?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[Von double nach Int casten!!!!!!]]></title><description><![CDATA[<p>Habe da einen Fehler beim casten von double nach int. Testet bitte mal den Quellcode und schaut mal was dabei rauskommt. Ich werde aus der Sache nicht schlau. Ich verwende Visual C++ 6.</p>
<p>So habe folgenen Quellcode:</p>
<p>double mbetrag;<br />
int mganzzahl;</p>
<p>mbetrag = 33.41;<br />
mbetrag *= 100;</p>
<p>mganzzahl = (int)mbetrag;</p>
<p>Normal sollte ja in mganzzahl 3341 stehen, aber es steht 3340 drin. Der Quellcode ist nur ein Beispiel! Vielleicht hab ich da auch etwas in sachen C++ verpasst oder steh auf der Leitung. Ist das ein arithmetischerFehler der CPU? Für mich sieht das so aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/54219/von-double-nach-int-casten</link><generator>RSS for Node</generator><lastBuildDate>Mon, 01 Jun 2026 14:49:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/54219.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 05 Nov 2003 13:57:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:07:57 GMT]]></title><description><![CDATA[<p>Habe da einen Fehler beim casten von double nach int. Testet bitte mal den Quellcode und schaut mal was dabei rauskommt. Ich werde aus der Sache nicht schlau. Ich verwende Visual C++ 6.</p>
<p>So habe folgenen Quellcode:</p>
<p>double mbetrag;<br />
int mganzzahl;</p>
<p>mbetrag = 33.41;<br />
mbetrag *= 100;</p>
<p>mganzzahl = (int)mbetrag;</p>
<p>Normal sollte ja in mganzzahl 3341 stehen, aber es steht 3340 drin. Der Quellcode ist nur ein Beispiel! Vielleicht hab ich da auch etwas in sachen C++ verpasst oder steh auf der Leitung. Ist das ein arithmetischerFehler der CPU? Für mich sieht das so aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387253</guid><dc:creator><![CDATA[Brosi]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:07:57 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:18:19 GMT]]></title><description><![CDATA[<p>Servus,</p>
<p>Nö kein Fehler. Der rechnet das richtig du hast ja bei dem float typ mehrere Stellen hinter dem Komma. d.h. Der Wert 33.41 = 33.409998. Also 33.41 * 100 = 3340.</p>
<p>Rechnung 33.41 * 100:</p>
<p>33.409998 * 100 = 3340 (9998)</p>
<p>mfg<br />
Hellsgore</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387282</guid><dc:creator><![CDATA[Hellsgore]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:18:19 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:25:19 GMT]]></title><description><![CDATA[<p>Ich vergasse...<br />
Eine Lösung wäre es den Wert bevor du mit ihm rechnest ihn runden zu lassen. Ich kenne aber jetzt im mom keine Funktion dafür. Mir hängt nur noch die hier im Kopf:</p>
<p>_fcvt</p>
<p>Damit kannste einen float in einen string machen. Musst mal schauen irgendwo gabs da ne Func....</p>
<p>mfg<br />
Hellsgore</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387288</guid><dc:creator><![CDATA[Hellsgore]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:25:19 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:26:54 GMT]]></title><description><![CDATA[<p>In diesem Fall würde es ausreichen, vor dem Cast .5 zu addieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387295</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:26:54 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:31:39 GMT]]></title><description><![CDATA[<p>Servus,</p>
<p>da sagste was.......... das is mir ja noch nie aufgefallen. Naja ich habs immer anders gemacht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Hellsgore</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387300</guid><dc:creator><![CDATA[Hellsgore]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:31:39 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:38:40 GMT]]></title><description><![CDATA[<p>Warum passiert das aber nicht mit allen Werten? Ich war neugierig und habe es mal ausprobiert.</p>
<p>Mit den Werten 33.42 und 33.40 als Ausgangswert stimmte beispielsweise wieder alles.</p>
<pre><code class="language-cpp">for (int i = 1; i &lt; 40000; i++) // 40000 ist willkürlich gewählt
	{
		double mbetrag = i / 100.0; 
		int mganzzahl; 

		mbetrag *= 100; 

		mganzzahl = static_cast&lt;int&gt; (mbetrag); 
		if (mganzzahl != i)
		{
			TRACE(&quot;%10d != %10d       Diff: %10d\n&quot;, i, mganzzahl, mganzzahl-i);
		}
	}
</code></pre>
<p>Das ist erstaunlich. So auf Anhieb habe ich da kein Muster erkennen können.</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> Bin verwirrt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/387307</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387307</guid><dc:creator><![CDATA[estartu]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:38:40 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:49:46 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/4497">@Hellsgore</a>: Naja wenn man es so sieht wie du, das mathematisch 33.41 = 33.409998 ist dann stimmt das ganze schon. Aber eigentlich sollte 33.41 = 33.41 sein oder? Also scheint irgendeine die CPU doch ein Problem mit den Kommastellen zu haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387327</guid><dc:creator><![CDATA[Brosi]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:49:46 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:53:02 GMT]]></title><description><![CDATA[<p>Brosi schrieb:</p>
<blockquote>
<p>Also scheint irgendeine die CPU doch ein Problem mit den Kommastellen zu haben.</p>
</blockquote>
<p>Nein.</p>
<p>&lt;Gebetsmühle&gt;<br />
Gleitkommatypen sind prinzipiell ungenau.<br />
&lt;/Gebetsmühle&gt;</p>
<p>Gleitkommatypen werden intern als eine Art &quot;Dualbruch&quot; dargestellt, also eine Kommazahl im Dualsystem. Leider sind die meisten abbrechenden Dezimalbrüche, darunter auch 33.41, im Dualsystem nicht abbrechend, sondern periodisch. Da die Anzahl der Stellen begrenzt ist, wird die nächstliegende darstellbare Zahl gewählt. Die kann vom Wert her darüber oder darunterliegen. Wenn sie darüberliegt, merkst du beim Abschneiden der Nachkommastellen nichts davon, liegt sie darunter, fehlt eben was.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387335</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:53:02 GMT</pubDate></item><item><title><![CDATA[Reply to Von double nach Int casten!!!!!! on Wed, 05 Nov 2003 14:57:12 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/2803">@MFK</a>: Danke für die Erklärung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> auch wenn dich das Beten müde macht, aber es hat mir das Hintergrundwissen gebracht, das ich suchte. Danke nochmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/387339</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/387339</guid><dc:creator><![CDATA[Brosi]]></dc:creator><pubDate>Wed, 05 Nov 2003 14:57:12 GMT</pubDate></item></channel></rss>