Java 中 NumberFormat getRoundingMode()方法,带示例
原文:https://www . geesforgeks . org/number format-getroundingmode-method-in-Java-with-examples/
getRoundingMode() 方法是Java . text . Number Format的内置方法,返回给定数字格式中正在使用的舍入模式。
语法 :
public RoundingMode getRoundingMode()
参数:该功能不接受任何参数。
返回值:该函数返回用于该数字格式的舍入模式。
下面是上述功能的实现:
程序 1:
// Java program to implement
// the above function
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
public class Main {
public static void main(String[] args)
throws Exception
{
// Get the instance for Locale US
NumberFormat nF
= NumberFormat.getInstance(
Locale.US);
// Prints the Rounding Mode
System.out.println("The rounding mode"
+ " value is: "
+ nF.getRoundingMode());
}
}
输出:
The rounding mode value is: HALF_EVEN
程序二:
// Java program to implement
// the above function
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
public class Main {
public static void main(String[] args)
throws Exception
{
// Get the instance for Locale CANADA
NumberFormat nF
= NumberFormat.getInstance(
Locale.CANADA);
// Prints the Rounding Mode
System.out.println("The rounding mode"
+ " value is: "
+ nF.getRoundingMode());
}
}
输出:
The rounding mode value is: HALF_EVEN
参考:https://docs . Oracle . com/javase/10/docs/API/Java/text/numberformat . html # getRoundingMode()
版权属于:月萌API www.moonapi.com,转载请注明出处