<?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[double runden]]></title><description><![CDATA[<p>Hallo ,</p>
<p>ich möchte einen double auf 4 Nachkommastellen runden.<br />
Das runden klappt auch , aber das Endergebnis hat dat sehr viele<br />
nachkommastellen , die mit Nullen ausgefüllt sind.<br />
Wie kriege ich nur 4 Nachkommastellen ?</p>
<pre><code>double x = 12.3400000001; 
unsigned int nStellen =4 ; 
double y = Round( x, nStellen); 

double CTestDoc::Round( double zahl, unsigned int nStellen ) 
{ 
long mul = potenzieren( 10 , nStellen ); 
zahl*= mul; 
if( zahl&gt;0 ){ zahl += 0.5;} 
else{ zahl-=0.5;} 
long x = static_cast&lt;long&gt;(zahl); 
zahl = 0; 
zahl = static_cast&lt;double&gt;( x); 

zahl/=mul; 

return zahl; 
} 

long CTestDoc::potenzieren(int basis, int exponent) 
{ 
int erg=1; 
for(int i=0; i&lt;exponent; ++i){ 
erg*= basis; 
} 
return erg; 
}
</code></pre>
<p>Gruß, Elke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/209572/double-runden</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 16:00:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/209572.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Apr 2008 10:58:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 10:58:17 GMT]]></title><description><![CDATA[<p>Hallo ,</p>
<p>ich möchte einen double auf 4 Nachkommastellen runden.<br />
Das runden klappt auch , aber das Endergebnis hat dat sehr viele<br />
nachkommastellen , die mit Nullen ausgefüllt sind.<br />
Wie kriege ich nur 4 Nachkommastellen ?</p>
<pre><code>double x = 12.3400000001; 
unsigned int nStellen =4 ; 
double y = Round( x, nStellen); 

double CTestDoc::Round( double zahl, unsigned int nStellen ) 
{ 
long mul = potenzieren( 10 , nStellen ); 
zahl*= mul; 
if( zahl&gt;0 ){ zahl += 0.5;} 
else{ zahl-=0.5;} 
long x = static_cast&lt;long&gt;(zahl); 
zahl = 0; 
zahl = static_cast&lt;double&gt;( x); 

zahl/=mul; 

return zahl; 
} 

long CTestDoc::potenzieren(int basis, int exponent) 
{ 
int erg=1; 
for(int i=0; i&lt;exponent; ++i){ 
erg*= basis; 
} 
return erg; 
}
</code></pre>
<p>Gruß, Elke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484334</guid><dc:creator><![CDATA[Elke100]]></dc:creator><pubDate>Tue, 01 Apr 2008 10:58:17 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 11:06:31 GMT]]></title><description><![CDATA[<p>Elke100 schrieb:</p>
<blockquote>
<p>Das runden klappt auch , aber das Endergebnis hat dat sehr viele<br />
nachkommastellen, die mit Nullen ausgefüllt sind.</p>
</blockquote>
<p>Intern (im Speicher) werden diese Nullen auch immer existieren. Runden heißt nicht, dass da plötzlich Bits verschwinden. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Elke100 schrieb:</p>
<blockquote>
<p>Wie kriege ich nur 4 Nachkommastellen?</p>
</blockquote>
<p>Bei der Ausgabe:</p>
<pre><code class="language-cpp">std::cout.precision( 4 );
std::cout &lt;&lt; std::fixed &lt;&lt; 12.3400000001 &lt;&lt; std::endl;
</code></pre>
<p>cheers, Swordfish</p>
<p>PS: cpp-Tags sind was Tolles <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484338</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Tue, 01 Apr 2008 11:06:31 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 11:06:16 GMT]]></title><description><![CDATA[<p>Wenn du mit cout arbeitest, könnte dir setprecision helfen:</p>
<pre><code class="language-cpp">cout &lt;&lt; setprecision(4) &lt;&lt; f &lt;&lt; endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1484340</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484340</guid><dc:creator><![CDATA[lagalopex]]></dc:creator><pubDate>Tue, 01 Apr 2008 11:06:16 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 11:12:38 GMT]]></title><description><![CDATA[<p>Danke für eure Antworten !</p>
<p>Aber mir geht es nicht drum , die Zahl als Meldung auszugeben.<br />
Ich schreibe die Zahl in eine andere Struktur , die auch als<br />
xml ausgegeben werden kann.<br />
Und die Frage ist , wir kann ich nur die 4 Nachkommastellen<br />
in die andere Struktur schreiben.</p>
<p>Danke.</p>
<p>Elke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484347</guid><dc:creator><![CDATA[Elke100]]></dc:creator><pubDate>Tue, 01 Apr 2008 11:12:38 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 11:14:29 GMT]]></title><description><![CDATA[<p>Gar nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484350</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Tue, 01 Apr 2008 11:14:29 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 11:19:15 GMT]]></title><description><![CDATA[<p>lagalopex schrieb:</p>
<blockquote>
<p>Wenn du mit cout arbeitest, könnte dir setprecision helfen:</p>
<pre><code class="language-cpp">cout &lt;&lt; setprecision(4) &lt;&lt; f &lt;&lt; endl;
</code></pre>
</blockquote>
<p>Für <code>std::setprecision( )</code> musst Du <code>&lt;iomanip&gt;</code> einbinden. Ohne <code>std::fixed</code> wird mit <code>std::setprecision( )</code> (und <code>std::ostream::precision( )</code> ) die Gesamtbreite festgelegt, nicht nur die Anzahl der Nachkommastellen.</p>
<p>Elke100 schrieb:</p>
<blockquote>
<p>Ich schreibe die Zahl in eine andere Struktur , die auch als<br />
xml ausgegeben werden kann.</p>
</blockquote>
<p>Wie sieht diese Struktur denn aus? Wie serialisierst Du sie?</p>
<p>cheers, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484352</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Tue, 01 Apr 2008 11:19:15 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 11:26:24 GMT]]></title><description><![CDATA[<p>Hallo ,</p>
<p>habe noch ein Problem festgestellt.</p>
<p>Wenn ich die Zahl : 12.44999999999999999 nehme , dann bekomme ich<br />
nach der folgenden Codezeile :</p>
<pre><code>zahl = static_cast&lt;double&gt;( x);
</code></pre>
<p>zahl = 124500 Was auch richtig ist.</p>
<p>Bei der nächsten Codezeile :</p>
<pre><code>zahl/=mul;
</code></pre>
<p>bekomme ich als Ergebnis wieder meine ursprüngliche Zahl:<br />
zahl =12.44999999999999999</p>
<p>Es ist doch zum Verzweifeln !!!!</p>
<p>Was mache ich falsch ?</p>
<p>Gruß , Elke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484366</guid><dc:creator><![CDATA[Elke100]]></dc:creator><pubDate>Tue, 01 Apr 2008 11:26:24 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 11:57:16 GMT]]></title><description><![CDATA[<p>komma um 4 Stellen nach links schieben, in einen Integer umwandeln, wieder zurück in double und komma wieder nach rechts schieben</p>
<p>du könntest das ganze auch in nen String umwandeln, womit sich auch recht einfach alle nicht benötigten Zeichen entfernen lassen</p>
<p>mal etwas mehr Kreativität zeigen ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484393</guid><dc:creator><![CDATA[zwutz]]></dc:creator><pubDate>Tue, 01 Apr 2008 11:57:16 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 12:27:00 GMT]]></title><description><![CDATA[<p>Hallo zwutz,</p>
<p>und was soll ich tun , wenn ich<br />
den Wert in String umwandle ?<br />
Nullen entfernen ?</p>
<p>Wenn ich wieder zu double zurückkehre habe ich wieder alles beim Alten.<br />
Ausserdem , arbeite ich nicht mit Spieldaten . Es gibt auch so Begriffe wie Typsicherheit . Ich kann nicht z.B. Preise einfach in verschieden Typen<br />
umwandeln und Zeichen entfernen !<br />
Mein Chef nennt sieht es bestimmt nicht als kreativ an . <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>Grüße, Elke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484439</guid><dc:creator><![CDATA[Elke100]]></dc:creator><pubDate>Tue, 01 Apr 2008 12:27:00 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 12:33:52 GMT]]></title><description><![CDATA[<p>Elke100 schrieb:</p>
<blockquote>
<p>Es gibt auch so Begriffe wie Typsicherheit. Ich kann nicht z.B. Preise einfach in verschieden Typen umwandeln und Zeichen entfernen!</p>
</blockquote>
<p>Geldbeträge speichert man auch nicht als <code>double</code> ...</p>
<p>Swordfish schrieb:</p>
<blockquote>
<p>Wie sieht diese Struktur denn aus? Wie serialisierst Du sie?</p>
</blockquote>
<p>cheers, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484446</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Tue, 01 Apr 2008 12:33:52 GMT</pubDate></item><item><title><![CDATA[Reply to double runden on Tue, 01 Apr 2008 12:48:34 GMT]]></title><description><![CDATA[<p>Hallo Swordfish</p>
<blockquote>
<p>Geldbeträge speichert man auch nicht als double...</p>
</blockquote>
<p>Ja natürlich . Wir haben dafür auch Money-Variablen Typen.<br />
Problem ist , wir benutzen zum Versenden der Daten ein Fremdframework ,<br />
dass nur float und double kennt .</p>
<blockquote>
<p>Wie sieht diese Struktur denn aus? Wie serialisierst Du sie?</p>
</blockquote>
<p>das ist eine ObjektStruktur , die auf Klassen aus dem Fremdframework basiert</p>
<p>Und ich muss einfach einen double in diese Striuktur setzen.</p>
<p>Gruß , Elke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1484465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1484465</guid><dc:creator><![CDATA[Elke100]]></dc:creator><pubDate>Tue, 01 Apr 2008 12:48:34 GMT</pubDate></item></channel></rss>