format Number with two decimal places - Android java.lang

Android examples for java.lang:Double

Description

format Number with two decimal places

Demo Code


//package com.java2s;

import java.text.DecimalFormat;

public class Main {

    public static String formatNumber2D(double value) {
        return formatNumber(value, "0.00");
    }/*from   w  w  w. j  a  v  a  2s  . com*/

    public static String formatNumber(double value, String format) {
        DecimalFormat decimalFormat = new DecimalFormat(format);
        return decimalFormat.format(value);
    }

    public static String formatNumber(double value) {
        return formatNumber(value, "0");
    }
}

Related Tutorials