Java Code Examples for com.ibm.icu.text.NumberFormat#getInstance()
The following examples show how to use
com.ibm.icu.text.NumberFormat#getInstance() .
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: GlobalizationPreferences.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * This function can be overridden by subclasses to use different heuristics. * <b>It MUST return a 'safe' value, * one whose modification will not affect this object.</b> * * @param style * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected NumberFormat guessNumberFormat(int style) { NumberFormat result; ULocale nfLocale = getAvailableLocale(TYPE_NUMBERFORMAT); if (nfLocale == null) { nfLocale = ULocale.ROOT; } switch (style) { case NF_NUMBER: result = NumberFormat.getInstance(nfLocale); break; case NF_SCIENTIFIC: result = NumberFormat.getScientificInstance(nfLocale); break; case NF_INTEGER: result = NumberFormat.getIntegerInstance(nfLocale); break; case NF_PERCENT: result = NumberFormat.getPercentInstance(nfLocale); break; case NF_CURRENCY: result = NumberFormat.getCurrencyInstance(nfLocale); result.setCurrency(getCurrency()); break; default: throw new IllegalArgumentException("Unknown number format style"); } return result; }
Example 3
Source File: ChartUIUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Returns the default number format instance for default locale. * * @return the default number format */ public static NumberFormat getDefaultNumberFormatInstance( ) { NumberFormat numberFormat = NumberFormat.getInstance( ); // fix icu limitation which only allow 3 fraction digits as maximum by // default. ?100 is enough. numberFormat.setMaximumFractionDigits( 100 ); return numberFormat; }
Example 4
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; }
Example 5
Source File: ChartUtil.java From birt with Eclipse Public License 1.0 | 4 votes |
private static NumberFormat initDefaultNumberFormat( ) { NumberFormat format = NumberFormat.getInstance( Locale.getDefault( ) ); format.setGroupingUsed( false ); return format; }