getRoundingMode()方法是java.text.NumberFormat的內置方法,返回在給定Number格式中使用的舍入模式。
用法:
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
示例2:
// 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()
相關用法
- Java NumberFormat getAvailableLocales()用法及代碼示例
- Java NumberFormat equals()用法及代碼示例
- Java NumberFormat hashCode()用法及代碼示例
- Java NumberFormat clone()用法及代碼示例
- Java NumberFormat getMaximumFractionDigits()用法及代碼示例
- Java NumberFormat getNumberInstance()用法及代碼示例
- Java NumberFormat getInstance()用法及代碼示例
- Java NumberFormat getIntegerInstance()用法及代碼示例
- Java NumberFormat getCurrencyInstance()用法及代碼示例
- Java NumberFormat isParseIntegerOnly()用法及代碼示例
- Java NumberFormat setMaximumFractionDigits()用法及代碼示例
- Java NumberFormat setMinimumFractionDigits()用法及代碼示例
- Java NumberFormat setParseIntegerOnly()用法及代碼示例
- Java NumberFormat parse()用法及代碼示例
- Java NumberFormat setCurrency()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 NumberFormat getRoundingMode() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。