Example usage for java.text NumberFormat getNumberInstance

List of usage examples for java.text NumberFormat getNumberInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getNumberInstance.

Prototype

public static NumberFormat getNumberInstance(Locale inLocale) 

Source Link

Document

Returns a general-purpose number format for the specified locale.

Usage

From source file:org.polymap.kaps.importer.test.NumberFormatterTest.java

public void testThousands() {
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.getDefault());
    nf.setMaximumIntegerDigits(10);/*from w w w  .  j ava  2s.c  o m*/
    nf.setMaximumFractionDigits(10);
    nf.setMinimumIntegerDigits(10);
    nf.setMinimumFractionDigits(10);

    System.out.println(nf.format(12345));
}

From source file:org.toobsframework.transformpipeline.xslExtentions.PriceFormatHelper.java

/**
 * Gets a string that represents the input Price formatted into the proper fromate, and converted
 * into the proper timezone./*from w w w .  j  ava 2s.  com*/
 *
 * @return Price-only string formatted with given time zone.
 *
 * @exception XMLTransfromerException if parsing problem occurs
 */
public static String getFormattedPrice(String inputPrice, String priceFormat, String language)
        throws XMLTransformerException {
    if ((inputPrice == null) || (inputPrice.trim().length() == 0)) {
        inputPrice = "0";
    }

    Locale locale = new Locale(language.substring(2, 4).toLowerCase(), language.substring(0, 2));
    DecimalFormat priceFormatter = (DecimalFormat) NumberFormat.getNumberInstance(locale);
    priceFormatter.setGroupingUsed(true);
    priceFormatter.setMaximumFractionDigits(2);
    priceFormatter.setMinimumFractionDigits(2);

    priceFormatter.applyPattern(priceFormat);

    return priceFormatter.format(new Double(inputPrice));
}

From source file:org.polymap.kaps.model.VertragsdatenErweitertImportFix.java

public static void add(UnitOfWork uow, QueryBuilder<VertragComposite> builder, VertragComposite template,
        String eingangsNr, String zuschlag, String abschlag, String zubem, String abbem) throws ParseException {

    BooleanExpression expr = QueryExpressions.eq(template.eingangsNr(),
            ((Long) NumberFormat.getNumberInstance(Locale.ENGLISH).parse(eingangsNr)).intValue());
    VertragComposite latest = builder.where(expr).newQuery(uow).maxResults(1).find();
    if (latest != null) {
        log.info("Changing Vertrag " + latest.eingangsNr().get());
        VertragsdatenErweitertComposite vertragsdatenErweitertComposite = latest.erweiterteVertragsdaten()
                .get();//from w  w  w.j a va  2 s .c o m
        if (zuschlag != null) {
            vertragsdatenErweitertComposite.zuschlag().set(Double.valueOf(zuschlag));
        }
        if (zubem != null) {
            vertragsdatenErweitertComposite.zuschlagBemerkung().set(zubem);
        }
        if (abschlag != null) {
            vertragsdatenErweitertComposite.abschlag().set(Double.valueOf(abschlag));
        }
        if (abbem != null) {
            vertragsdatenErweitertComposite.abschlagBemerkung().set(abbem);
        }
        recalculate(vertragsdatenErweitertComposite);
    }
}

From source file:DecimalFormatDemo.java

static public void localizedFormat(String pattern, double value, Locale loc) {
    NumberFormat nf = NumberFormat.getNumberInstance(loc);
    DecimalFormat df = (DecimalFormat) nf;
    df.applyPattern(pattern);/*from   w  ww  .j  a v a  2 s  .  c o m*/
    String output = df.format(value);
    System.out.println(pattern + "  " + output + "  " + loc.toString());
}

From source file:org.thymeleaf.engine21.conversion.conversion3.LongFormatter.java

public Long parse(final String text, final Locale locale) throws ParseException {
    final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
    return Long.valueOf(numberFormat.parse(text).longValue());
}

From source file:org.thymeleaf.engine21.conversion.conversion3.LongFormatter.java

public String print(final Long object, final Locale locale) {
    final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
    return numberFormat.format(object.longValue());
}

From source file:org.polymap.p4.process.BoundingBoxSupplier.java

public BoundingBoxSupplier() {
    nf = NumberFormat.getNumberInstance(Polymap.getSessionLocale());
    nf.setMaximumIntegerDigits(100);//  w  ww.j av  a 2 s  . c  om
    nf.setMaximumFractionDigits(2);
    nf.setMinimumIntegerDigits(1);
    nf.setMinimumFractionDigits(2);
}

From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.FloatDataConverter.java

@Override
public String valueToString(Float value) {
    if (value == null)
        return "";
    DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(LocaleContextHolder.getLocale());
    df.setGroupingUsed(false);//from  ww w  .ja va2s . c o m
    df.setMaximumFractionDigits(Integer.MAX_VALUE);
    return df.format(value);
}

From source file:com.jeeframework.util.validate.GenericTypeValidator.java

/**
 *  Checks if the value can safely be converted to a byte primitive.
 *
 *@param  value   The value validation is being performed on.
 *@param  locale  The locale to use to parse the number (system default if
 *      null)//from  www. j  a va2 s  .  c  o  m
 *@return the converted Byte value.
 */
public static Byte formatByte(String value, Locale locale) {
    Byte result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getNumberInstance(locale);
        } else {
            formatter = NumberFormat.getNumberInstance(Locale.getDefault());
        }
        formatter.setParseIntegerOnly(true);
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error      and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= Byte.MIN_VALUE && num.doubleValue() <= Byte.MAX_VALUE) {
                result = new Byte(num.byteValue());
            }
        }
    }

    return result;
}

From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.DoubleDataConverter.java

@Override
public String valueToString(Double value) {
    if (value == null)
        return "";
    DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(LocaleContextHolder.getLocale());
    df.setGroupingUsed(false);//from   w  ww  . j ava  2s.c  o  m
    df.setMaximumFractionDigits(Integer.MAX_VALUE);
    return df.format(value);
}