Java DecimalFormat getMaximumFractionDigits()方法

Java DecimalFormat getMaximumFractionDigits()方法

getMaximumFractionDigits() 方法是Java中 java.text.DecimalFomrat 类的一个内置方法,用于获取一个Number的小数或小数部分允许的最大数字。

语法:

public int getMaximumFractionDigits()

参数 :该函数不接受任何参数。

返回值 :该函数返回一个数字的小数部分所允许的最大数字数。

下面是上述函数的实现。

程序1 :

// Java program to illustrate the
// getMaximumFractionDigits() 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 Grouping Size
        System.out.println(deciFormat.getMaximumFractionDigits());
    }
}

输出:

3

程序2 :

// Java program to illustrate the
// getMaximumFractionDigits() 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 Grouping Size
        System.out.println(deciFormat.getMaximumFractionDigits());
    }
}

输出:

2

参考资料 : https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#getMaximumFractionDigits()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程