-- Android

숫자로 된 문자열에 천단위로 콤마를 표시

어린왕자악꿍 2015. 7. 16. 10:25
getCommaNumeric("10000");
결과 : 10,000

public static String getCommaNumeric(String str) {
    if(str.equals(""))
        return "";
   
    long value = 0;
   
    try {
        value = Long.parseLong(str);
    } catch(Exception e) {
        return str;
    }
   
    DecimalFormat format = new DecimalFormat("###,###");
    return format.format(value);
}