Search in sources :

Example 1 with DecimalFormat

use of com.ibm.icu.text.DecimalFormat in project head by mifos.

the class MifosNumberFormattingInfoTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    try {
        Locale locale = LabelTagUtils.getInstance().getUserPreferredLocale();
        DecimalFormat decimalFormat = getDecimalFormat(locale);
        DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols();
        StringBuilder sb = new StringBuilder();
        sb.append("<span id=\"format.decimalSeparator\" title=\"").append(symbols.getDecimalSeparator()).append("\"></span>\n");
        sb.append("<span id=\"format.groupingSeparator\" title=\"").append(symbols.getGroupingSeparator()).append("\"></span>\n");
        sb.append("<span id=\"format.groupingSize\" title=\"").append(decimalFormat.getGroupingSize()).append("\"></span>\n");
        pageContext.getOut().print(sb.toString());
    } catch (Exception ex) {
        throw new JspException("NumberFormattingInfoTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}
Also used : Locale(java.util.Locale) JspException(javax.servlet.jsp.JspException) DecimalFormatSymbols(com.ibm.icu.text.DecimalFormatSymbols) DecimalFormat(com.ibm.icu.text.DecimalFormat) JspException(javax.servlet.jsp.JspException)

Example 2 with DecimalFormat

use of com.ibm.icu.text.DecimalFormat in project es6draft by anba.

the class NumberFormatObject method createNumberFormat.

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));
    }
    // 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;
}
Also used : ULocale(com.ibm.icu.util.ULocale) DecimalFormat(com.ibm.icu.text.DecimalFormat)

Aggregations

DecimalFormat (com.ibm.icu.text.DecimalFormat)2 DecimalFormatSymbols (com.ibm.icu.text.DecimalFormatSymbols)1 ULocale (com.ibm.icu.util.ULocale)1 Locale (java.util.Locale)1 JspException (javax.servlet.jsp.JspException)1