<?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[falsche Rechnung]]></title><description><![CDATA[<p>tagchen,<br />
ich bin heute auf ein Problem gestoßen, dass falsch gerechnet wird. In der Rechnung soll die Anzahl der Striche eines Fortschrittsbalkens berechnet werden.<br />
Dazu teile ich die Länge des Balkens durch den Maxwert, multipliziere ihn mit dem aktuellen Wert und teile dann durch 2.75 aus designtechnischen Gründen. Das Ergebnis ist allerdings immer 0.</p>
<pre><code class="language-cpp">float anzahl = ((this-&gt;w/this-&gt;max)*this-&gt;pos)/2.75;
</code></pre>
<p>this-&gt;w = 100<br />
this-&gt;max = 4741<br />
this-&gt;pos = zwischen 0 und 4741</p>
<p>Die allererste Rechnung (100/4741=0.02) ergibt allerdings immer 0, weswegen der Rest dann auch 0 bleibt. Kann mir jemand verraten wieso? Ich habe schon andere Datentypen ausprobiert, aber immer ist das Ergebnis 0...</p>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/210674/falsche-rechnung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 21:46:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/210674.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Apr 2008 20:24:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to falsche Rechnung on Sun, 13 Apr 2008 20:24:18 GMT]]></title><description><![CDATA[<p>tagchen,<br />
ich bin heute auf ein Problem gestoßen, dass falsch gerechnet wird. In der Rechnung soll die Anzahl der Striche eines Fortschrittsbalkens berechnet werden.<br />
Dazu teile ich die Länge des Balkens durch den Maxwert, multipliziere ihn mit dem aktuellen Wert und teile dann durch 2.75 aus designtechnischen Gründen. Das Ergebnis ist allerdings immer 0.</p>
<pre><code class="language-cpp">float anzahl = ((this-&gt;w/this-&gt;max)*this-&gt;pos)/2.75;
</code></pre>
<p>this-&gt;w = 100<br />
this-&gt;max = 4741<br />
this-&gt;pos = zwischen 0 und 4741</p>
<p>Die allererste Rechnung (100/4741=0.02) ergibt allerdings immer 0, weswegen der Rest dann auch 0 bleibt. Kann mir jemand verraten wieso? Ich habe schon andere Datentypen ausprobiert, aber immer ist das Ergebnis 0...</p>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491519</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Sun, 13 Apr 2008 20:24:18 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Sun, 13 Apr 2008 20:34:11 GMT]]></title><description><![CDATA[<p>Hmmm kann es sein das einge werte keine fließkommazahlen sind ?</p>
<p>Lösung:</p>
<pre><code class="language-cpp">float anzahl = ((static_cast&lt;float&gt;(this-&gt;w)/static_cast&lt;float&gt;(this-&gt;max))static_cast&lt;float&gt;(*this-&gt;pos))/2.75;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1491524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491524</guid><dc:creator><![CDATA[DataByte]]></dc:creator><pubDate>Sun, 13 Apr 2008 20:34:11 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Sun, 13 Apr 2008 21:05:44 GMT]]></title><description><![CDATA[<p>DataByte schrieb:</p>
<blockquote>
<p>Hmmm kann es sein das einge werte keine fließkommazahlen sind ?</p>
<p>Lösung:</p>
<pre><code class="language-cpp">float anzahl = ((static_cast&lt;float&gt;(this-&gt;w)/static_cast&lt;float&gt;(this-&gt;max))static_cast&lt;float&gt;(*this-&gt;pos))/2.75;
</code></pre>
</blockquote>
<p>ja, bis auf die 2.75 sind alles ganze Zahlen. Aber hätte er bei der Rechnung nicht automatisch alles als Gleitkommazahl behandeln sollen?</p>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491531</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Sun, 13 Apr 2008 21:05:44 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Sun, 13 Apr 2008 23:25:39 GMT]]></title><description><![CDATA[<p>Wenn 'this-&gt;w' und 'this-&gt;max' ganzzahlige Typen sind, wird dort die Ganzzahldivision ausgeführt. Bei 100/4741 ist das 0 <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="😉"
    /> . Und 0*irgwas/irgwas ist nun mal auch 0^^.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491561</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Sun, 13 Apr 2008 23:25:39 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Mon, 14 Apr 2008 06:28:49 GMT]]></title><description><![CDATA[<p>Wäre ein Wert des inneren Ausdrucks ein float gewesen, hätte der Compiler alles mit float gerechnet.<br />
Der Compiler betrachtet jeden Ausdruck einzeln.<br />
Allso hätte ein einizigercast genügt:</p>
<pre><code class="language-cpp">float anzahl = ((static_cast&lt;float&gt;(this-&gt;w)/this-&gt;max)*this-&gt;pos)/2.75;
</code></pre>
<p>BTW: Warum verwendest Du this-&gt;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491595</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 14 Apr 2008 06:28:49 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Mon, 14 Apr 2008 10:19:42 GMT]]></title><description><![CDATA[<p>weil die Rechnung bei mehreren Objekten ausgeführt wird und &quot;this-&gt;&quot; kürzer ist, als &quot;langerObjektname[index]-&gt;&quot;<br />
thx 4 help, funktioniert jetzt alles.</p>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491706</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Mon, 14 Apr 2008 10:19:42 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Mon, 14 Apr 2008 10:21:00 GMT]]></title><description><![CDATA[<p>häh</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491707</guid><dc:creator><![CDATA[rofler]]></dc:creator><pubDate>Mon, 14 Apr 2008 10:21:00 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Mon, 14 Apr 2008 10:44:40 GMT]]></title><description><![CDATA[<p>KN4CK3R schrieb:</p>
<blockquote>
<p>und &quot;this-&gt;&quot; kürzer ist, als &quot;langerObjektname[index]-&gt;&quot;</p>
</blockquote>
<p>Dan lass doch this-&gt; einfach weg! Das ist dann noch kürzer. this-&gt; ist immer überflüssig!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491718</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 14 Apr 2008 10:44:40 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Mon, 14 Apr 2008 10:47:52 GMT]]></title><description><![CDATA[<p>rofler schrieb:</p>
<blockquote>
<p>häh</p>
</blockquote>
<p>würde es dir etwas ausmachen, dir ein anderes Forum zu suchen, um dort die Leute mit deinen qualifizierten Beiträgen zu beklücken?</p>
<p>@this-&gt;: irgendwie ne ältere Angewohnheit... <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>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491722</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Mon, 14 Apr 2008 10:47:52 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Mon, 14 Apr 2008 10:52:51 GMT]]></title><description><![CDATA[<p>KN4CK3R schrieb:</p>
<blockquote>
<p>rofler schrieb:</p>
<blockquote>
<p>häh</p>
</blockquote>
<p>würde es dir etwas ausmachen, dir ein anderes Forum zu suchen, um dort die Leute mit deinen qualifizierten Beiträgen zu beklücken?</p>
<p>@this-&gt;: irgendwie ne ältere Angewohnheit... <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>greetz KN4CK3R</p>
</blockquote>
<p>Ich hab dich lediglich auf das gleiche hingewiesen wie Martin. Dein this-&gt; ist völlig unnötig und du hast den Sinn davon obendrein offensichtlich noch nicht richtig verstanden, deiner früheren Antwort nach zu urteilen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491727</guid><dc:creator><![CDATA[rofler]]></dc:creator><pubDate>Mon, 14 Apr 2008 10:52:51 GMT</pubDate></item><item><title><![CDATA[Reply to falsche Rechnung on Mon, 14 Apr 2008 11:09:04 GMT]]></title><description><![CDATA[<p>jop, klar, mit &quot;häh&quot;... <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>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1491736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1491736</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Mon, 14 Apr 2008 11:09:04 GMT</pubDate></item></channel></rss>