Java-math-bigdecimal-precision
提供:Dev Guides
Java.math.BigDecimal.precision()メソッド
説明
- java.math.BigDecimal.precision()*メソッドは、このBigDecimalの精度を返します。 精度は、スケールなしの値の桁数です。ゼロ値の精度は1です。
宣言
以下は* java.math.BigDecimal.precision()*メソッドの宣言です。
public int precision()
パラメーター
NA
戻り値
このメソッドは、このBigDecimalオブジェクトの精度を返します。
例外
NA
例
次の例は、math.BigDecimal.precision()メソッドの使用法を示しています。
package com.finddevguides;
import java.math.*;
public class BigDecimalDemo {
public static void main(String[] args) {
//create 2 BigDecimal Objects
BigDecimal bg1, bg2;
bg1 = new BigDecimal("123.234");
bg2 = new BigDecimal("523");
//create 2 int objects
int i1, i2;
//assign the result of precision of bg1, bg2 to i1 and i2
i1 = bg1.precision();
i2 = bg2.precision();
String str1 = "The precision of " + bg1 + " is " + i1;
String str2 = "The precision of " + bg2 + " is " + i2;
//print the values of i1, i2
System.out.println( str1 );
System.out.println( str2 );
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
The precision of 123.234 is 6
The precision of 523 is 3