Java DecimalFormat getMaximumIntegerDigits()方法
getMaximumIntegerDigits() 方法是Java中 java.text.DecimalFomrat 类的一个内置方法,用于获取一个Number的积分部分所允许的最大数字数。一个数字中的积分部分被定义为小数点(…)之前的部分。例如,在数字123,45.678中,积分部分是123,45。
语法:
public int getMaximumIntegerDigits()
参数 :该函数不接受任何参数。
返回值 :该函数返回一个数字的积分部分所允许的最大数字数。
下面是上述函数的实现。
程序1 :
// Java program to illustrate the// getMaximumIntegerDigits() method import java.text.DecimalFormat;import java.util.Currency;import java.util.Locale; public class Main { public static void main(String[] args) { // Create the DecimalFormat Instance DecimalFormat deciFormat = new DecimalFormat(); // Print the Maximum Integral digits allowed System.out.println(deciFormat.getMaximumIntegerDigits()); }}
输出:
2147483647
程序2 :
// Java program to illustrate the// getMaximumIntegerDigits() method import java.text.DecimalFormat;import java.util.Currency;import java.util.Locale; public class Main { public static void main(String[] args) { // Create the DecimalFormat Instance DecimalFormat deciFormat = new DecimalFormat(); deciFormat.applyPattern("##.##"); // Print the Maximum Integral digits allowed System.out.println(deciFormat.getMaximumIntegerDigits()); }}输出:
2147483647
参考资料 : https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#getMaximumIntegerDigits()
