<?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[Werte runden]]></title><description><![CDATA[<p>HI<br />
kurze frage:<br />
wie kann ich eine variable vom typ double,mit dem wert z.B. 0.003 genau auf null runden? und wie kann man prüfen dass die zwei stellen nach dem komma auch null sind?<br />
dankeschön schonma <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="🙂"
    /><br />
MfG Bl1nk182</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/161106/werte-runden</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 19:02:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/161106.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Oct 2006 13:31:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Werte runden on Tue, 03 Oct 2006 13:31:12 GMT]]></title><description><![CDATA[<p>HI<br />
kurze frage:<br />
wie kann ich eine variable vom typ double,mit dem wert z.B. 0.003 genau auf null runden? und wie kann man prüfen dass die zwei stellen nach dem komma auch null sind?<br />
dankeschön schonma <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="🙂"
    /><br />
MfG Bl1nk182</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148660</guid><dc:creator><![CDATA[Bl1nk182]]></dc:creator><pubDate>Tue, 03 Oct 2006 13:31:12 GMT</pubDate></item><item><title><![CDATA[Reply to Werte runden on Tue, 03 Oct 2006 16:53:46 GMT]]></title><description><![CDATA[<p>runder ist leicht:</p>
<p>du berechnest den integer der Zahl und ziehst den von der Zahl ab, jetzt schaust du ob das Ergebnis &gt;= 0.5 ist</p>
<p>double zahl = 3.534;</p>
<p>if(zahl - (double)(int)zahl &gt;= 0.5)<br />
{<br />
// aufrunden<br />
zahl = (double)(int)zahl +1;<br />
}<br />
else<br />
{<br />
// abrunden<br />
zahl = (double)(int)zahl;<br />
}</p>
<p>natürlich kannst du das noch optimieren.</p>
<p>das mit den Nullen ist schwieriger:</p>
<p>double zahl = 3.678;<br />
int zahl2 = (int)(zahl * 10);<br />
zahl2 -= (int)zahl*10</p>
<p>da kann man schön bestauen was Klammern für ne Wirkung haben^^</p>
<p>das gibt dir die 1. Nachkommastelle aus, 100 die 2., 1000 die 3. und so weiter</p>
<p>EDIT:</p>
<p>PS: erbitte Feetback obs funktioniert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148776</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148776</guid><dc:creator><![CDATA[ESS_CB]]></dc:creator><pubDate>Tue, 03 Oct 2006 16:53:46 GMT</pubDate></item><item><title><![CDATA[Reply to Werte runden on Wed, 04 Oct 2006 13:02:11 GMT]]></title><description><![CDATA[<p>sry,dass ich mich gestern nich mehr gemeldet hab,ging nich mehr <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f623.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--persevering_face"
      title="&gt;.&lt;"
      alt="😣"
    /><br />
dein kleines prog tuts aber <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
dankeschön <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149244</guid><dc:creator><![CDATA[Bl1nk182]]></dc:creator><pubDate>Wed, 04 Oct 2006 13:02:11 GMT</pubDate></item><item><title><![CDATA[Reply to Werte runden on Wed, 04 Oct 2006 14:31:56 GMT]]></title><description><![CDATA[<pre><code>if(zahl - (double)(int)zahl &gt;= 0.5)
{
  zahl = (double)(int)zahl +1;
}
else
{
  zahl = (double)(int)zahl;
}
</code></pre>
<p>=&gt;</p>
<pre><code>zahl= (int)(zahl+0.5);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1149307</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149307</guid><dc:creator><![CDATA[hellihjb]]></dc:creator><pubDate>Wed, 04 Oct 2006 14:31:56 GMT</pubDate></item><item><title><![CDATA[Reply to Werte runden on Wed, 04 Oct 2006 14:36:07 GMT]]></title><description><![CDATA[<p>das ganze jetzt noch mit reinterpret_cast und es schaut sogar noch hübsch aus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149314</guid><dc:creator><![CDATA[Knuddlbaer]]></dc:creator><pubDate>Wed, 04 Oct 2006 14:36:07 GMT</pubDate></item><item><title><![CDATA[Reply to Werte runden on Wed, 04 Oct 2006 14:38:21 GMT]]></title><description><![CDATA[<p>ESS_CB schrieb:</p>
<blockquote>
<p>du berechnest den integer der Zahl und ziehst den von der Zahl ab, jetzt schaust du ob das Ergebnis &gt;= 0.5 ist</p>
</blockquote>
<p>Das klappt aber nur mit Werten, die in den Wertebereich von int passen. Das sind bei weitem nicht alle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149316</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 04 Oct 2006 14:38:21 GMT</pubDate></item><item><title><![CDATA[Reply to Werte runden on Thu, 05 Oct 2006 14:16:12 GMT]]></title><description><![CDATA[<p>kk <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149963</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149963</guid><dc:creator><![CDATA[ESS_CB]]></dc:creator><pubDate>Thu, 05 Oct 2006 14:16:12 GMT</pubDate></item><item><title><![CDATA[Reply to Werte runden on Thu, 05 Oct 2006 21:13:16 GMT]]></title><description><![CDATA[<p>Bl1nk182 schrieb:</p>
<blockquote>
<p>wie kann ich eine variable vom typ double,mit dem wert z.B. 0.003 genau auf null runden? und wie kann man prüfen dass die zwei stellen nach dem komma auch null sind?</p>
</blockquote>
<p>Hallo Bl1nk182</p>
<p>Runden geht mit dem Ausdruck</p>
<pre><code class="language-cpp">#include &lt;cmath&gt; // std::floor
double z = 0.003;
double zGerundet = std::floor( z + 0.5 );
</code></pre>
<p>funktioniert für positive und negative Zahlen.<br />
<a href="http://de.wikipedia.org/wiki/Gau%C3%9Fklammer" rel="nofollow">Hier ganz unten auf der Seite</a> steht's und da steht auch, dass man floor die 'Gauß-Klammer' nennt.</p>
<p>Falls Du das Runden für eine Ausgabe (std::cout) benötigst, solltest Du gar nicht (!) runden, sondern std::setprecision und std::fixed benutzen, um die von Dir gewünschte Anzahl der Nachkommastellen zu erreichen.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1150228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1150228</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 05 Oct 2006 21:13:16 GMT</pubDate></item></channel></rss>