Here you can find the source of formatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping, boolean dotDecimalSymbol)
public static String formatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping, boolean dotDecimalSymbol)
//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); } }