<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.byte-welt.net/index.php?action=history&amp;feed=atom&amp;title=Gleitkommazahlen_mit_Java_runden</id>
	<title>Gleitkommazahlen mit Java runden - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.byte-welt.net/index.php?action=history&amp;feed=atom&amp;title=Gleitkommazahlen_mit_Java_runden"/>
	<link rel="alternate" type="text/html" href="https://wiki.byte-welt.net/index.php?title=Gleitkommazahlen_mit_Java_runden&amp;action=history"/>
	<updated>2026-07-07T22:23:56Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Byte-Welt Wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.byte-welt.net/index.php?title=Gleitkommazahlen_mit_Java_runden&amp;diff=9547&amp;oldid=prev</id>
		<title>L-ectron-x am 1. Juli 2026 um 14:35 Uhr</title>
		<link rel="alternate" type="text/html" href="https://wiki.byte-welt.net/index.php?title=Gleitkommazahlen_mit_Java_runden&amp;diff=9547&amp;oldid=prev"/>
		<updated>2026-07-01T14:35:59Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;de&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Nächstältere Version&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version vom 1. Juli 2026, 14:35 Uhr&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Zeile 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Zeile 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In unserem [https://www.java-blog-buch.de/11-02-mathematisches-mit-java-lang-math/ Artikel über die Klasse java.lang.Math] haben wir auf unserer eLerning-Plattform [https://&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;www.&lt;/del&gt;java-blog-buch.de/ Java-Blog-Buch] bereits einige Dinge zum Thema Runden mit Java besprochen. Mit einigen Code-Beispielen möchten wir hier noch einmal abrunden.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In unserem [https://www.java-blog-buch.de/11-02-mathematisches-mit-java-lang-math/ Artikel über die Klasse java.lang.Math] haben wir auf unserer eLerning-Plattform [https://java-blog-buch&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.bytes4fun&lt;/ins&gt;.de/ Java-Blog-Buch] bereits einige Dinge zum Thema Runden mit Java besprochen. Mit einigen Code-Beispielen möchten wir hier noch einmal abrunden.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Cast=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Cast=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key bytewelt_wiki:diff:1.41:old-9353:rev-9547:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>L-ectron-x</name></author>
	</entry>
	<entry>
		<id>https://wiki.byte-welt.net/index.php?title=Gleitkommazahlen_mit_Java_runden&amp;diff=9353&amp;oldid=prev</id>
		<title>L-ectron-X am 7. November 2021 um 16:42 Uhr</title>
		<link rel="alternate" type="text/html" href="https://wiki.byte-welt.net/index.php?title=Gleitkommazahlen_mit_Java_runden&amp;diff=9353&amp;oldid=prev"/>
		<updated>2021-11-07T16:42:05Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;de&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Nächstältere Version&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version vom 7. November 2021, 16:42 Uhr&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot;&gt;Zeile 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Zeile 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Cast=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Cast=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Eine einfache und ungenaue Methode zu runden ist, der &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Fließkommazahl &lt;/del&gt;die Nachkommastellen einfach abzuschneiden. Beim Casten wird also immer abgerundet. In einigen Fällen kann das genügen, in den meisten jedoch nicht.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Eine einfache und ungenaue Methode zu runden ist, der &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Gleitkommazahl &lt;/ins&gt;die Nachkommastellen einfach abzuschneiden. Beim Casten wird also immer abgerundet. In einigen Fällen kann das genügen, in den meisten jedoch nicht.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    /**&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    /**&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    * Schneidet Nachkommastellen einer &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Fließkommazahl &lt;/del&gt;ab.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    * Schneidet Nachkommastellen einer &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Gleitkommazahl &lt;/ins&gt;ab.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    *&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    *&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    * @param value ist der &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Fließkommazahlenwert&lt;/del&gt;, dem die Nachkommastellen abgeschnitten werden sollen&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    * @param value ist der &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Gleitkommazahlenwert&lt;/ins&gt;, dem die Nachkommastellen abgeschnitten werden sollen&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    */&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    */&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    private int cutOffDecimalPlaces(double value) {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    private int cutOffDecimalPlaces(double value) {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l16&quot;&gt;Zeile 16:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Zeile 16:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Math.round()=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Math.round()=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Die Klasse {{JAPI|java.lang.Math}} bietet eine [[Methode]] zum ([https://de.wikipedia.org/wiki/Rundung#Kaufm%C3%A4nnisches_Runden kaufmännischem]) Runden von &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Fließkommazahlen &lt;/del&gt;an. Mit dieser können wir recht einfach eine eigene Methode schreiben, die uns Dezimalzahlen auf eine beliebige Anzahl Nachkommastellen rundet.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Die Klasse {{JAPI|java.lang.Math}} bietet eine [[Methode]] zum ([https://de.wikipedia.org/wiki/Rundung#Kaufm%C3%A4nnisches_Runden kaufmännischem]) Runden von &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Gleitkommazahlen &lt;/ins&gt;an. Mit dieser können wir recht einfach eine eigene Methode schreiben, die uns Dezimalzahlen auf eine beliebige Anzahl Nachkommastellen rundet.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    /**&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    /**&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l95&quot;&gt;Zeile 95:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Zeile 95:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=DecimalFormat=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=DecimalFormat=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Noch eine einfache Variante für das Runden von &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Fließkommazahlen &lt;/del&gt;mit Java - mit [[DecimalFormat]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Noch eine einfache Variante für das Runden von &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Gleitkommazahlen &lt;/ins&gt;mit Java - mit [[DecimalFormat]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{JAPI|DecimalFormat}} ist eine Subklasse von NumberFormat für die Formatierung von Dezimalzahlen. Als Unterklasse von NumberFormat stehen auch hier Formatierungen von Dezimalzahlen in Abhängigkeit des Gebietsschemas zur Verfügung.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{JAPI|DecimalFormat}} ist eine Subklasse von NumberFormat für die Formatierung von Dezimalzahlen. Als Unterklasse von NumberFormat stehen auch hier Formatierungen von Dezimalzahlen in Abhängigkeit des Gebietsschemas zur Verfügung.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>L-ectron-X</name></author>
	</entry>
	<entry>
		<id>https://wiki.byte-welt.net/index.php?title=Gleitkommazahlen_mit_Java_runden&amp;diff=9352&amp;oldid=prev</id>
		<title>L-ectron-X: Die Seite wurde neu angelegt: „In unserem [https://www.java-blog-buch.de/11-02-mathematisches-mit-java-lang-math/ Artikel über die Klasse java.lang.Math] haben wir auf unserer eLerning-Plat…“</title>
		<link rel="alternate" type="text/html" href="https://wiki.byte-welt.net/index.php?title=Gleitkommazahlen_mit_Java_runden&amp;diff=9352&amp;oldid=prev"/>
		<updated>2021-11-07T16:41:00Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „In unserem [https://www.java-blog-buch.de/11-02-mathematisches-mit-java-lang-math/ Artikel über die Klasse java.lang.Math] haben wir auf unserer eLerning-Plat…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In unserem [https://www.java-blog-buch.de/11-02-mathematisches-mit-java-lang-math/ Artikel über die Klasse java.lang.Math] haben wir auf unserer eLerning-Plattform [https://www.java-blog-buch.de/ Java-Blog-Buch] bereits einige Dinge zum Thema Runden mit Java besprochen. Mit einigen Code-Beispielen möchten wir hier noch einmal abrunden.&lt;br /&gt;
&lt;br /&gt;
=Cast=&lt;br /&gt;
Eine einfache und ungenaue Methode zu runden ist, der Fließkommazahl die Nachkommastellen einfach abzuschneiden. Beim Casten wird also immer abgerundet. In einigen Fällen kann das genügen, in den meisten jedoch nicht.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   /**&lt;br /&gt;
   * Schneidet Nachkommastellen einer Fließkommazahl ab.&lt;br /&gt;
   *&lt;br /&gt;
   * @param value ist der Fließkommazahlenwert, dem die Nachkommastellen abgeschnitten werden sollen&lt;br /&gt;
   */&lt;br /&gt;
   private int cutOffDecimalPlaces(double value) {&lt;br /&gt;
      return (int) value;&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Nach Übergabe der Zahl 1234.565 erhalten wir 1234 als Rückgbewert.&lt;br /&gt;
&lt;br /&gt;
=Math.round()=&lt;br /&gt;
Die Klasse {{JAPI|java.lang.Math}} bietet eine [[Methode]] zum ([https://de.wikipedia.org/wiki/Rundung#Kaufm%C3%A4nnisches_Runden kaufmännischem]) Runden von Fließkommazahlen an. Mit dieser können wir recht einfach eine eigene Methode schreiben, die uns Dezimalzahlen auf eine beliebige Anzahl Nachkommastellen rundet.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   /**&lt;br /&gt;
   * Rundet den übergebenen Wert auf die Anzahl der übergebenen Nachkommastellen&lt;br /&gt;
   *&lt;br /&gt;
   * @param value ist der zu rundende Wert.&lt;br /&gt;
   * @param decimalPoints ist die Anzahl der Nachkommastellen, auf die gerundet werden soll.&lt;br /&gt;
   */&lt;br /&gt;
   private double round(double value, int decimalPoints) {&lt;br /&gt;
      double d = Math.pow(10, decimalPoints);&lt;br /&gt;
      return Math.round(value * d) / d;&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Der Aufruf der Methode in einer [[Klasse]] zum Runden einer Zahl auf zwei Nachkommastellen sieht dann z.B. so aus:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   System.out.println(round(1234.565, 2);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Math.rint()=&lt;br /&gt;
Die Methode rint() rundet double-Werte mathematisch.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Rundet den übergebenen Wert auf die Anzahl der übergebenen Nachkommastellen&lt;br /&gt;
 *&lt;br /&gt;
 * @param value ist der zu rundende Wert.&lt;br /&gt;
 * @param decimalPoints ist die Anzahl der Nachkommastellen, auf die mathematisch gerundet werden soll.&lt;br /&gt;
 */&lt;br /&gt;
private double rint(double value, int decimalPoints) {&lt;br /&gt;
   double d = Math.pow(10, decimalPoints);&lt;br /&gt;
   return Math.rint(value * d) / d;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Math.floor()=&lt;br /&gt;
Die Methode floor() rundet auf die nächst kleinere Zahl.&lt;br /&gt;
&lt;br /&gt;
=Math.ceil()=&lt;br /&gt;
Die Methode ceil() rundet auf die nächst größere Zahl.&lt;br /&gt;
&lt;br /&gt;
=String#format()=&lt;br /&gt;
In Programmen müssen Ergebnisse von Berechnungen oft für eine Ausgabe passend formatiert werden. Dazu gehört auch &amp;#039;&amp;#039;&amp;#039;das Runden, bspw. von Euro-Beträgen&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Locale;&lt;br /&gt;
&lt;br /&gt;
public class Formatter {&lt;br /&gt;
   public static void main(String[] args) {&lt;br /&gt;
      double number = 1234.565;&lt;br /&gt;
      System.out.println(number+&amp;quot; gerundet: &amp;quot;+String.format(&amp;quot;%1.2f €&amp;quot;, number));&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Möchte man bspw. das englische oder französische Zahlenformat ausgeben, muss noch ein passendes {{JAPI|Locale}} als erster Parameter der format()-[[Methode]] übergeben werden.&lt;br /&gt;
 String.format(Locale.FRENCH, &amp;quot;%1.2f&amp;quot;, number)&lt;br /&gt;
Ansonsten wird das von der [[JRE]] erkannte Locale des [[Betriebssystem|Betriebssystems]] verwendet.&lt;br /&gt;
&lt;br /&gt;
=NumberFormat=&lt;br /&gt;
Auch relativ einfach ist das Runden von Dezimalzahlen mit [[NumberFormat]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.text.NumberFormat;&lt;br /&gt;
&lt;br /&gt;
public class Formatter {&lt;br /&gt;
   public static void main(String[] args) {&lt;br /&gt;
      double number = 1234.565;&lt;br /&gt;
      NumberFormat formatter = NumberFormat.getInstance();&lt;br /&gt;
      formatter.setMaximumFractionDigits(2);&lt;br /&gt;
      System.out.println(number+&amp;quot; gerundet: &amp;quot;+formatter.format(number));&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Mit Hilfe der Methode &amp;lt;code&amp;gt;NumberFormat#setMaximumFractionDigits(int value)&amp;lt;/code&amp;gt; auf eine festgelegte Anzahl an Nachkommastellen begrenzen. Dabei wird auch eine Rundung der Zahl vorgenommen.&lt;br /&gt;
Möchte man bspw. das englische oder französische Zahlenformat ausgeben, muss noch ein passendes {{JAPI|Locale}} als Parameter der &amp;lt;code&amp;gt;getInstance()&amp;lt;/code&amp;gt;-[[Methode]] übergeben werden.&lt;br /&gt;
 NumberFormat formatter = NumberFormat.getInstance(Locale.FRENCH);&lt;br /&gt;
Ansonsten wird das von der [[JRE]] erkannte Locale des [[Betriebssystem|Betriebssystems]] verwendet.&lt;br /&gt;
&lt;br /&gt;
=DecimalFormat=&lt;br /&gt;
Noch eine einfache Variante für das Runden von Fließkommazahlen mit Java - mit [[DecimalFormat]].&lt;br /&gt;
&lt;br /&gt;
{{JAPI|DecimalFormat}} ist eine Subklasse von NumberFormat für die Formatierung von Dezimalzahlen. Als Unterklasse von NumberFormat stehen auch hier Formatierungen von Dezimalzahlen in Abhängigkeit des Gebietsschemas zur Verfügung.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.text.DecimalFormat;&lt;br /&gt;
&lt;br /&gt;
public class Formatter {&lt;br /&gt;
   public static void main(String[] args) {&lt;br /&gt;
      double number = 1234.565;&lt;br /&gt;
      DecimalFormat formatter = new DecimalFormat(&amp;quot;#.##&amp;quot;);&lt;br /&gt;
      System.out.println(number+&amp;quot; gerundet: &amp;quot;+formatter.format(number));&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
DecimalFormat unterstützt verschiedene lokalisierbare Zahlen-Typen, so auch Ganzzahlen (123), Festkommazahlen (123,4), wissenschaftliche Notation (1,23E4), Prozentangaben (12%) und Währungsbeträge (123 $).&lt;br /&gt;
&lt;br /&gt;
{{Fragen stellen}}&lt;br /&gt;
&lt;br /&gt;
=Siehe auch=&lt;br /&gt;
*{{JAPI|NumberFormat}}&lt;br /&gt;
*{{JAPI|DecimalFormat}}&lt;br /&gt;
*[[String]]&lt;br /&gt;
*{{JAPI|String}}&lt;br /&gt;
&lt;br /&gt;
[[Kategorie:Java-Codeschnipsel]]&lt;/div&gt;</summary>
		<author><name>L-ectron-X</name></author>
	</entry>
</feed>