Java Code Examples for com.ibm.icu.text.DecimalFormat#setMaximumFractionDigits()
The following examples show how to use
com.ibm.icu.text.DecimalFormat#setMaximumFractionDigits() .
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: NumberFormatSpecifierImpl.java From birt with Eclipse Public License 1.0 | 6 votes |
public String format( double dValue, ULocale lo ) { final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance( lo ); if ( isSetFractionDigits( ) ) { df.setMinimumFractionDigits( getFractionDigits( ) ); df.setMaximumFractionDigits( getFractionDigits( ) ); } df.applyLocalizedPattern( df.toLocalizedPattern( ) ); final StringBuffer sb = new StringBuffer( ); if ( getPrefix( ) != null ) { sb.append( getPrefix( ) ); } sb.append( isSetMultiplier( ) ? df.format( dValue * getMultiplier( ) ) : df.format( dValue ) ); if ( getSuffix( ) != null ) { sb.append( getSuffix( ) ); } return sb.toString( ); }
Example 2
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 3
Source File: NumberFormatSpecifierImpl.java From birt with Eclipse Public License 1.0 | 5 votes |
public String format( Number number, ULocale lo ) { Number n = NumberUtil.transformNumber( number ); if ( n instanceof Double ) { return format( ( (Double) number ).doubleValue( ), lo ); } // Format big decimal. BigDecimal bdNum = (BigDecimal) n; final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance( lo ); if ( isSetFractionDigits( ) ) { df.setMinimumFractionDigits( getFractionDigits( ) ); df.setMaximumFractionDigits( getFractionDigits( ) ); } String pattern = NumberUtil.adjustBigNumberFormatPattern( df.toLocalizedPattern( ) ); if ( pattern.indexOf( 'E' ) < 0 ) { pattern = pattern + NumberUtil.BIG_DECIMAL_FORMAT_SUFFIX; } df.applyLocalizedPattern( pattern ); final StringBuffer sb = new StringBuffer( ); if ( getPrefix( ) != null ) { sb.append( getPrefix( ) ); } sb.append( isSetMultiplier( ) ? df.format( bdNum.multiply( BigDecimal.valueOf( getMultiplier( ) ), NumberUtil.DEFAULT_MATHCONTEXT ) ) : df.format( bdNum ) ); if ( getSuffix( ) != null ) { sb.append( getSuffix( ) ); } return sb.toString( ); }
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; }