« Programmation Java/Nombre de taille arbitraire » : différence entre les versions

Contenu supprimé Contenu ajouté
Ligne 261 :
BigDecimal un_dixieme = new BigDecimal(Double.toString(0.1D)); // 0.1
</syntaxhighlight>
 
=== Précision et échelle ===
 
La méthode <code>precision()</code> retourne la précision, c'est-à-dire le nombre de chiffres décimaux du nombre.
La méthode <code>scale()</code> retourne la position de la virgule par rapport au dernier chiffre de précision.
Exemples :
 
{|
! Nombre
! <code>.precision()</code>
! <code>.scale()</code>
|-
| <syntaxhighlight lang="java" inline>new BigDecimal("1250000")</syntaxhighlight>
| style="text-align:center;" | <code>7</code>
| style="text-align:center;" | <code>0</code>
|-
| <syntaxhighlight lang="java" inline>new BigDecimal("125E4")</syntaxhighlight>
| style="text-align:center;" | <code>3</code>
| style="text-align:center;" | <code>-4</code>
|-
| <syntaxhighlight lang="java" inline>new BigDecimal("0.000125")</syntaxhighlight>
| style="text-align:center;" | <code>3</code>
| style="text-align:center;" | <code>6</code>
|-
| <syntaxhighlight lang="java" inline>new BigDecimal("0.0001250000")</syntaxhighlight>
| style="text-align:center;" | <code>7</code>
| style="text-align:center;" | <code>10</code>
|}
 
== Notes ==