Browse Source

[공통][New] StringUtil.toComma() 추가

hyodong.min 7 years ago
parent
commit
e50bb5d8b6
1 changed files with 35 additions and 0 deletions
  1. 35 0
      app/src/main/java/kr/co/zumo/app/lifeplus/util/StringUtil.java

+ 35 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/util/StringUtil.java

@@ -12,6 +12,7 @@ import android.text.Spanned;
 import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.text.DecimalFormat;
 import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -260,4 +261,38 @@ public class StringUtil {
   public static String bold(String string) {
     return new StringBuilder().append("<b>").append(string).append("</b>").toString();
   }
+
+  /**
+   * 세자리 숫자마다 콤마(,)를 추가해준다.
+   *
+   * @param s "1000"
+   * @return "1,000"
+   */
+  public static String toComma(String s) {
+    DecimalFormat decimalFormat = new DecimalFormat("#,##0");
+    return decimalFormat.format(Integer.parseInt(s));
+  }
+
+  /**
+   * 세자리 숫자마다 콤마(,)를 추가해준다.
+   *
+   * @param s 1000
+   * @return "1,000"
+   */
+  public static String toComma(int s) {
+    DecimalFormat decimalFormat = new DecimalFormat("#,##0");
+    return decimalFormat.format(s);
+  }
+
+  /**
+   * 세자리 숫자마다 콤마(,)를 추가해준다.
+   *
+   * @param s 1000
+   * @return "1,000"
+   */
+  public static String toComma(long s) {
+    DecimalFormat decimalFormat = new DecimalFormat("#,##0");
+    return decimalFormat.format(s);
+  }
+
 }