Java tutorial
//package com.java2s; public class Main { public static String toNumberComma(String text) { String ret = ""; String number = ""; for (int i = 0; i < text.length(); ++i) { char ch = text.charAt(i); if (ch >= '0' && ch <= '9') { number += ch; } else { if (number.length() != 0) { if (number.charAt(0) != '0') { ret += getPriceToWon(Long.valueOf(number)); } else { ret += number; } number = ""; } ret += ch; } } if (number.length() != 0) { if (number.charAt(0) != '0') { ret += getPriceToWon(Long.valueOf(number)); } else { ret += number; } } return ret; } public static String getPriceToWon(Long value) { String ret = ""; int cnt = 0; boolean resv = false; Long now = value; while (now != 0) { if (resv) { ret = String.valueOf(now % 10) + "," + ret; resv = false; } else { ret = String.valueOf(now % 10) + ret; } now /= 10; if (++cnt == 3) { resv = true; cnt = 0; } } return ret; } }