<?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[Runden funktioniert nicht exakt]]></title><description><![CDATA[<p>hallo leute,</p>
<p>ich möchte einen zahl auf die 2 nachkommastelle runden. aus 2.445 soll 2.45 werden, aus 2.444 soll 2.44 werden (also &lt;5 abrunden und &gt;=5 aufrunden).<br />
ich wollte das wie folgt realisieren. das problem liegt scheinbar in der zeile b= ((a*100)-floor(a*100));<br />
für b ergibt sich zwar 0.5 , aber er springt dann nicht in die &gt;=0.5 if bedingung. wenn ich double b=0.5; setze funktioniert es.<br />
habt ihr eine idee woran es liegen könnte?</p>
<p>quellcode:</p>
<p>void main()</p>
<p>{</p>
<p>double a=2.445;<br />
double b;</p>
<p>{<br />
// printf(&quot;floor a = %lf\n&quot;, floor(a));<br />
// b= ((a*100)-floor(a*100));<br />
printf(&quot;b = %lf\n&quot;,b);</p>
<p>if(b&gt;=0.5)<br />
{<br />
printf(&quot;1\n&quot;);<br />
printf(&quot;a (ungerundet)= %lf\n&quot;, a);<br />
a=ceil(a*100)/100;<br />
printf(&quot;a = %lf\n&quot;,a);<br />
}</p>
<p>if(b&lt;0.5)<br />
{<br />
printf(&quot;2\n&quot;);<br />
printf(&quot;a (ungerundet)= %lf\n&quot;, a);<br />
a=floor(a*100)/100;<br />
printf(&quot;a = %lf\n&quot;,a);<br />
}</p>
<p>}<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/216552/runden-funktioniert-nicht-exakt</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 08:46:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/216552.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Jun 2008 12:09:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Runden funktioniert nicht exakt on Wed, 25 Jun 2008 12:09:30 GMT]]></title><description><![CDATA[<p>hallo leute,</p>
<p>ich möchte einen zahl auf die 2 nachkommastelle runden. aus 2.445 soll 2.45 werden, aus 2.444 soll 2.44 werden (also &lt;5 abrunden und &gt;=5 aufrunden).<br />
ich wollte das wie folgt realisieren. das problem liegt scheinbar in der zeile b= ((a*100)-floor(a*100));<br />
für b ergibt sich zwar 0.5 , aber er springt dann nicht in die &gt;=0.5 if bedingung. wenn ich double b=0.5; setze funktioniert es.<br />
habt ihr eine idee woran es liegen könnte?</p>
<p>quellcode:</p>
<p>void main()</p>
<p>{</p>
<p>double a=2.445;<br />
double b;</p>
<p>{<br />
// printf(&quot;floor a = %lf\n&quot;, floor(a));<br />
// b= ((a*100)-floor(a*100));<br />
printf(&quot;b = %lf\n&quot;,b);</p>
<p>if(b&gt;=0.5)<br />
{<br />
printf(&quot;1\n&quot;);<br />
printf(&quot;a (ungerundet)= %lf\n&quot;, a);<br />
a=ceil(a*100)/100;<br />
printf(&quot;a = %lf\n&quot;,a);<br />
}</p>
<p>if(b&lt;0.5)<br />
{<br />
printf(&quot;2\n&quot;);<br />
printf(&quot;a (ungerundet)= %lf\n&quot;, a);<br />
a=floor(a*100)/100;<br />
printf(&quot;a = %lf\n&quot;,a);<br />
}</p>
<p>}<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1535509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1535509</guid><dc:creator><![CDATA[P.T.]]></dc:creator><pubDate>Wed, 25 Jun 2008 12:09:30 GMT</pubDate></item><item><title><![CDATA[Reply to Runden funktioniert nicht exakt on Wed, 25 Jun 2008 12:17:08 GMT]]></title><description><![CDATA[<p>Keine 2 Sekunden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p><a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39342.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39342.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1535517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1535517</guid><dc:creator><![CDATA[rean]]></dc:creator><pubDate>Wed, 25 Jun 2008 12:17:08 GMT</pubDate></item></channel></rss>