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

Android examples for java.lang:Double

Description

format double Number in #,##0.0 format

Demo Code

import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String formatNumber(double d) {
        try {// w ww. j a va2 s .  co  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