当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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()



相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 DecimalFormat getMinimumIntegerDigits() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。