Java Code Examples for com.ibm.icu.text.DecimalFormat#setRoundingMode()
The following examples show how to use
com.ibm.icu.text.DecimalFormat#setRoundingMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluralRulesObject.java From es6draft with MIT License | 6 votes |
private NumberFormat createNumberFormat() { ULocale locale = ULocale.forLanguageTag(this.locale); locale = locale.setKeywordValue("numbers", "latn"); DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, NumberFormat.NUMBERSTYLE); if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) { numberFormat.setSignificantDigitsUsed(true); numberFormat.setMinimumSignificantDigits(minimumSignificantDigits); numberFormat.setMaximumSignificantDigits(maximumSignificantDigits); } else { numberFormat.setSignificantDigitsUsed(false); numberFormat.setMinimumIntegerDigits(minimumIntegerDigits); numberFormat.setMinimumFractionDigits(minimumFractionDigits); numberFormat.setMaximumFractionDigits(maximumFractionDigits); } // as required by ToRawPrecision/ToRawFixed numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP); return numberFormat; }
Example 2
Source File: NumberFormatObject.java From es6draft with MIT License | 5 votes |
private NumberFormat createNumberFormat() { ULocale locale = ULocale.forLanguageTag(this.locale); int choice; if ("decimal".equals(style)) { choice = NumberFormat.NUMBERSTYLE; } else if ("percent".equals(style)) { choice = NumberFormat.PERCENTSTYLE; } else { if ("code".equals(currencyDisplay)) { choice = NumberFormat.ISOCURRENCYSTYLE; } else if ("symbol".equals(currencyDisplay)) { choice = NumberFormat.CURRENCYSTYLE; } else { choice = NumberFormat.PLURALCURRENCYSTYLE; } } DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, choice); if ("currency".equals(style)) { numberFormat.setCurrency(Currency.getInstance(currency)); } // numberingSystem is already handled in language-tag // assert locale.getKeywordValue("numbers").equals(numberingSystem); if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) { numberFormat.setSignificantDigitsUsed(true); numberFormat.setMinimumSignificantDigits(minimumSignificantDigits); numberFormat.setMaximumSignificantDigits(maximumSignificantDigits); } else { numberFormat.setSignificantDigitsUsed(false); numberFormat.setMinimumIntegerDigits(minimumIntegerDigits); numberFormat.setMinimumFractionDigits(minimumFractionDigits); numberFormat.setMaximumFractionDigits(maximumFractionDigits); } numberFormat.setGroupingUsed(useGrouping); // as required by ToRawPrecision/ToRawFixed // FIXME: ICU4J bug: // new Intl.NumberFormat("en",{useGrouping:false}).format(111111111111111) // returns "111111111111111.02" numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP); return numberFormat; }