Java Locale Format formatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping, boolean dotDecimalSymbol)

Here you can find the source of formatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping, boolean dotDecimalSymbol)

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping,
            boolean dotDecimalSymbol) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Robert "Unlogic" Olofsson (unlogic@unlogic.se).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0-standalone.html
 ******************************************************************************/

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

import java.util.Locale;

public class Main {
    public static String formatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping,
            boolean dotDecimalSymbol) {

        DecimalFormat formatter = new DecimalFormat();

        formatter.setMinimumFractionDigits(minDecimals);

        formatter.setMaximumFractionDigits(maxDecimals);

        if (dotDecimalSymbol) {

            formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));

        }/*from   w  ww  . j  av  a  2 s. c  o  m*/

        formatter.setGroupingUsed(grouping);

        return formatter.format(value);

    }
}

Related

  1. formatNumber(double d, String pattern)
  2. formatNumber(long number)
  3. formatNumber(long value)
  4. formatNumber(Number num)
  5. formatNumber(Number number)
  6. formatNumber(Number value, String format)
  7. formatNumber(Object number, String pattern, Locale locale)
  8. formatNumber(Object value, Locale locale)
  9. formatNumber(Object value, String numberFormat)