Java DecimalFormat getMinimumIntegerDigits()方法
getMinimumIntegerDigits() 方法是Java中 java.text.DecimalFomrat 类的一个内置方法,用于获取一个Number的积分部分允许的最小数字数。一个数字中的积分部分被定义为小数点(…)之前的部分。例如,在数字123,45.678中,积分部分是123,45。
语法:
public int getMinimumIntegerDigits()
参数 :该函数不接受任何参数。
返回值 :该函数返回一个数字的整数部分所允许的最小数字。
下面是上述函数的实现。
程序1 :
// Java program to illustrate the// getMinimumIntegerDigits() 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 minimum Integral digits allowed System.out.println(deciFormat.getMinimumIntegerDigits()); }}
输出:
1
程序2 :
// Java program to illustrate the// getMinimumIntegerDigits() 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 Minimum Integral digits allowed System.out.println(deciFormat.getMinimumIntegerDigits()); }}输出:
1
参考资料 : https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#getMinimumIntegerDigits()
