<?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[Zahl runden]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe vor einiger Zeit mal folgenden Programmteil geschrieben:</p>
<pre><code class="language-cpp">string sub;
t = Zeile;
int h;
stringstream Str;	
			int pos = t.find(&quot;=&quot;);								// Umwandlung String in Zahl
				if(pos != string::npos)
				{
					sub = t.substr (pos + 1);
					Str &lt;&lt; sub;
					Str &gt;&gt; h;

				}
</code></pre>
<p>Die Zahl die ich an der gesuchten Stelle finde, war damals ganzzahlig. Dies ist jetzt aber eine float-zahl, die ich vorher noch mathematisch runden muss.</p>
<p>Probiert habe ich es mit roundf aus der math.h Libary, jedoch ohne Erfolg. Gibt es einen anderen Weg?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/284086/zahl-runden</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 07:48:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/284086.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 25 Mar 2011 12:37:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 12:37:04 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe vor einiger Zeit mal folgenden Programmteil geschrieben:</p>
<pre><code class="language-cpp">string sub;
t = Zeile;
int h;
stringstream Str;	
			int pos = t.find(&quot;=&quot;);								// Umwandlung String in Zahl
				if(pos != string::npos)
				{
					sub = t.substr (pos + 1);
					Str &lt;&lt; sub;
					Str &gt;&gt; h;

				}
</code></pre>
<p>Die Zahl die ich an der gesuchten Stelle finde, war damals ganzzahlig. Dies ist jetzt aber eine float-zahl, die ich vorher noch mathematisch runden muss.</p>
<p>Probiert habe ich es mit roundf aus der math.h Libary, jedoch ohne Erfolg. Gibt es einen anderen Weg?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039893</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039893</guid><dc:creator><![CDATA[Jenö Nyerges]]></dc:creator><pubDate>Fri, 25 Mar 2011 12:37:04 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 12:42:05 GMT]]></title><description><![CDATA[<p>Jenö Nyerges schrieb:</p>
<blockquote>
<p>Probiert habe ich es mit roundf aus der math.h Libary, jedoch ohne Erfolg.</p>
</blockquote>
<p>Definiere &quot;ohne Erfolg&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039896</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 25 Mar 2011 12:42:05 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 12:49:49 GMT]]></title><description><![CDATA[<p>klar sorry --&gt; trotz einbinden von math.h:</p>
<blockquote>
<p>undeclared identifier</p>
</blockquote>
<pre><code class="language-cpp">string sub;
t = Zeile;
float h;
stringstream Str;   
            int pos = t.find(&quot;=&quot;);                                // Umwandlung String in Zahl
                if(pos != string::npos)
                {
                    sub = t.substr (pos + 1);
                    Str &lt;&lt; sub;
                    Str &gt;&gt; h;
                    int j = roundf(h);
                }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2039904</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039904</guid><dc:creator><![CDATA[Jenö Nyerges]]></dc:creator><pubDate>Fri, 25 Mar 2011 12:49:49 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 12:55:49 GMT]]></title><description><![CDATA[<p>Das liegt wahrscheinlich daran, dass es roundf in der math.h (oder eigentlich cmath) gar nicht gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039907</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 25 Mar 2011 12:55:49 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 12:57:28 GMT]]></title><description><![CDATA[<p>Was steht denn in diesem String genau drin? <strong>Wild geraten</strong>: Wenn der String statt eines Dezimalpunktes, wie es in Amerika üblich ist, ein Dezimalkomma enthält, musst du dem Stream vorher eine deutsche Locale beibringen. Beispiel:</p>
<pre><code class="language-cpp">Str.imbue(std::locale(&quot;de_DE&quot;));
</code></pre>
<p>Ich glaube aber, dass der Locale-String systemabhängig ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039908</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Fri, 25 Mar 2011 12:57:28 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 13:05:00 GMT]]></title><description><![CDATA[<p>Bei den Systemen die ich kenne ist der locale standardmäßig &quot;C&quot; (also wie englisch).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039911</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 25 Mar 2011 13:05:00 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 13:19:48 GMT]]></title><description><![CDATA[<p>also es steht ein Dezimalpunkt drin, aber der Fehler kommt ja schon beim compilieren. Ich bin immer davon ausgegangen das roundf in der cmath ist ?!</p>
<blockquote>
<p><a href="http://www.codecogs.com/reference/c/math.h/round.php" rel="nofollow">http://www.codecogs.com/reference/c/math.h/round.php</a></p>
</blockquote>
<p>Gibt es eine ähnliche Funktion ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039919</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039919</guid><dc:creator><![CDATA[Jenö Nyerges]]></dc:creator><pubDate>Fri, 25 Mar 2011 13:19:48 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 13:23:23 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int j = static_cast &lt;int&gt; (h+.5);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2039921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039921</guid><dc:creator><![CDATA[MiP]]></dc:creator><pubDate>Fri, 25 Mar 2011 13:23:23 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 13:25:57 GMT]]></title><description><![CDATA[<p>Sieh besser hier nach wenn du wissen willst was in der cmath drin ist.<br />
<a href="http://www.cplusplus.com/reference/clibrary/cmath/" rel="nofollow">http://www.cplusplus.com/reference/clibrary/cmath/</a></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/18651">@MiP</a><br />
Wozu hier der static_cast? Das wird implizit sowieso gecastet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039923</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039923</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 25 Mar 2011 13:25:57 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 13:29:19 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/1387">@Braunstein</a></p>
<p>Um die Warnung beim Kompilieren zu vermeiden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039925</guid><dc:creator><![CDATA[MiP]]></dc:creator><pubDate>Fri, 25 Mar 2011 13:29:19 GMT</pubDate></item><item><title><![CDATA[Reply to Zahl runden on Fri, 25 Mar 2011 14:59:58 GMT]]></title><description><![CDATA[<p>Versuche es damit:</p>
<pre><code class="language-cpp">#include &lt;math.h&gt;
float  von;      // ungerundeter float-Wert
float  nach;     // gerundeter float-Wert 
float  factor;   // Hilfsgrösse zum runden
int    nk;       // Anzahl gewünschter Nachkommastellen, nach nk wird gerundet
factor = pow10(nk);
nach = floor(von*factor+0.5)/factor;
</code></pre>
<p>oder wenn es nur um die gerundete Ausgabe geht z.B. mit &lt;&lt; setprecision(2) &lt;&lt; ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2039973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2039973</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Fri, 25 Mar 2011 14:59:58 GMT</pubDate></item></channel></rss>