本文整理匯總了Java中java.text.NumberFormat.getRoundingMode方法的典型用法代碼示例。如果您正苦於以下問題:Java NumberFormat.getRoundingMode方法的具體用法?Java NumberFormat.getRoundingMode怎麽用?Java NumberFormat.getRoundingMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.text.NumberFormat
的用法示例。
在下文中一共展示了NumberFormat.getRoundingMode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: formatOutputTestLong
import java.text.NumberFormat; //導入方法依賴的package包/類
static void formatOutputTestLong(NumberFormat nf,
long longToTest,
String tiePosition,
String inputDigits,
String expectedOutput) {
int mfd = nf.getMaximumFractionDigits();
RoundingMode rm = nf.getRoundingMode();
String result = nf.format(longToTest);
if (!result.equals(expectedOutput)) {
System.out.println();
System.out.println("========================================");
System.out.println("***Failure : error formatting value from string : " +
inputDigits);
System.out.println("NumberFormat pattern is : " +
((DecimalFormat ) nf).toPattern());
System.out.println("Maximum number of fractional digits : " + mfd);
System.out.println("Fractional rounding digit : " + (mfd + 1));
System.out.println("Position of value relative to tie : " + tiePosition);
System.out.println("Rounding Mode : " + rm);
System.out.println(
"Error. Formatted result different from expected." +
"\nExpected output is : \"" + expectedOutput + "\"" +
"\nFormated output is : \"" + result + "\"");
System.out.println("========================================");
System.out.println();
errorCounter++;
allPassed = false;
} else {
testCounter++;
System.out.print("Success. Long input :" + inputDigits);
System.out.print(", rounding : " + rm);
System.out.print(", fract digits : " + mfd);
System.out.print(", tie position : " + tiePosition);
System.out.println(", expected : " + expectedOutput);
}
}
示例2: formatOutputTestObject
import java.text.NumberFormat; //導入方法依賴的package包/類
static void formatOutputTestObject(NumberFormat nf,
Object someNumber,
String tiePosition,
String inputDigits,
String expectedOutput) {
int mfd = nf.getMaximumFractionDigits();
RoundingMode rm = nf.getRoundingMode();
String result = nf.format(someNumber);
if (!result.equals(expectedOutput)) {
System.out.println();
System.out.println("========================================");
System.out.println("***Failure : error formatting value from string : " +
inputDigits);
System.out.println("NumberFormat pattern is : " +
((DecimalFormat ) nf).toPattern());
System.out.println("Maximum number of fractional digits : " + mfd);
System.out.println("Fractional rounding digit : " + (mfd + 1));
System.out.println("Position of value relative to tie : " + tiePosition);
System.out.println("Rounding Mode : " + rm);
System.out.println("Number self output representation: " + someNumber);
System.out.println(
"Error. Formatted result different from expected." +
"\nExpected output is : \"" + expectedOutput + "\"" +
"\nFormated output is : \"" + result + "\"");
System.out.println("========================================");
System.out.println();
errorCounter++;
allPassed = false;
} else {
testCounter++;
System.out.print("Success. Number input :" + inputDigits);
System.out.print(", rounding : " + rm);
System.out.print(", fract digits : " + mfd);
System.out.print(", tie position : " + tiePosition);
System.out.println(", expected : " + expectedOutput);
}
}
示例3: formatOutputTestDouble
import java.text.NumberFormat; //導入方法依賴的package包/類
static void formatOutputTestDouble(NumberFormat nf,
double doubleToTest,
String tiePosition,
String inputDigits,
String expectedOutput) {
int mfd = nf.getMaximumFractionDigits();
RoundingMode rm = nf.getRoundingMode();
String result = nf.format(doubleToTest);
if (!result.equals(expectedOutput)) {
System.out.println();
System.out.println("========================================");
System.out.println("***Failure : error formatting value from string : " +
inputDigits);
System.out.println("NumberFormat pattern is : " +
((DecimalFormat ) nf).toPattern());
System.out.println("Maximum number of fractional digits : " + mfd);
System.out.println("Fractional rounding digit : " + (mfd + 1));
System.out.println("Position of value relative to tie : " + tiePosition);
System.out.println("Rounding Mode : " + rm);
System.out.println("BigDecimal output : " +
new BigDecimal(doubleToTest).toString());
System.out.println("FloatingDecimal output : " + doubleToTest);
System.out.println(
"Error. Formatted result different from expected." +
"\nExpected output is : \"" + expectedOutput + "\"" +
"\nFormated output is : \"" + result + "\"");
System.out.println("========================================");
System.out.println();
errorCounter++;
allPassed = false;
} else {
testCounter++;
System.out.println("\nSuccess for double value : " + doubleToTest + " :");
System.out.println(" Input digits :" + inputDigits +
", BigDecimal value : " +
new BigDecimal(doubleToTest).toString());
System.out.print(" Rounding mode: " + rm);
System.out.print(", fract digits : " + mfd);
System.out.print(", position : " + tiePosition + " tie");
System.out.print(", result : " + result);
System.out.println(", expected : " + expectedOutput);
}
}