
- Java.math 包擴充套件
- Java.math - 列舉
- Java.math - 討論
Java.math.BigDecimal.precision() 方法
說明
java.math.BigDecimal.precision() 方法返回此 BigDecimal 的精度。精度是無標度值中的位數。零值的精度為 1。
宣告
以下是 java.math.BigDecimal.precision() 方法的宣告。
public int precision()
引數
不適用
返回值
此方法返回此 BigDecimal 物件的精度。
異常
不適用
示例
以下示例演示了 math.BigDecimal.precision() 方法的使用。
package com.tutorialspoint; 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
java_math_bigdecimal.htm
廣告