format double Number to string in #,##0.0 format - Android java.lang

Android examples for java.lang:Double

Description

format double Number to string in #,##0.0 format

Demo Code

import java.text.DecimalFormat;

public class Main{

    public static String formatNumber(double d) {
        try {/*w w  w  .ja  v a2  s  .c o m*/
            DecimalFormat df = new DecimalFormat("#,##0.0");
            return df.format(d);
        } catch (Exception e) {
        }
        return "";
    }
    public static String formatNumber(String d) {
        return formatNumber(Double.parseDouble(d));
    }

}

Related Tutorials