这个 JAVA数学大十进制。精度() 方法返回 这 大十进制。精度是指未标度值中的位数。
null
语法:
public int precision()
参数: 此方法不接受任何参数。
返回值: 此方法返回一个整数,该整数表示 这 大十进制对象。
例如:
Input : 198.176 Output : 6 Input : 721111.111 Output : 9
下面的程序演示了java。数学大十进制。Java中的precision()函数: 项目1:
import java.math.*; import java.io.*; class GFG { public static void main(String[] args) { // create 2 BigDecimal Objects BigDecimal b1, b2; // Assigning values to b1, b2 b1 = new BigDecimal( "198.176" ); b2 = new BigDecimal( "721111.111" ); // Display their respective precision System.out.println( "The precision of " + b1 + " is " + b1.precision()); System.out.println( "The precision of " + b2 + " is " + b2.precision()); } } |
输出:
The precision of 198.176 is 6 The precision of 721111.111 is 9
项目2:
// Java program to illustrate // precision() Function import java.math.*; import java.io.*; class GFG { public static void main(String[] args) { // Creating a BigDecimal Object BigDecimal num; // Assigning value 0.1 + 0.1 + 0.1 to num num = new BigDecimal( "0.1" ) .add( new BigDecimal( "0.1" )) .add( new BigDecimal( "0.1" )); // Display the BigDecimal value and its precision System.out.println( "The precision of " + num + " is " + num.precision()); } } |
输出:
The precision of 0.3 is 1
参考: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#precision()
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END