Format number to given decimal places (from) - Java java.lang

Java examples for java.lang:double Format

Description

Format number to given decimal places (from)

Demo Code


//package com.java2s;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class Main {
    /**//from w ww. j  a  v  a  2 s  . co m
     * Format number to given decimal places (from)
     *
     * @param value the value
     * @param minDecimals the decimals from
     * @return the string
     */
    public static String formatNumberDecimalMin(Number value,
            int minDecimals) {
        DecimalFormat df = new DecimalFormat("0.00",
                new DecimalFormatSymbols(new Locale("nl", "BE")));
        df.setMinimumFractionDigits(minDecimals);
        df.setMaximumFractionDigits(Integer.MAX_VALUE);
        return df.format(value);
    }
}

Related Tutorials