Skip to content

Instantly share code, notes, and snippets.

@yelinaung
Created April 23, 2014 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yelinaung/11202002 to your computer and use it in GitHub Desktop.
Save yelinaung/11202002 to your computer and use it in GitHub Desktop.
Insert comma on every three digits
private String insertComma(String digits) {
String result = digits;
if (digits.length() <= 3) {
return digits;
} else {
for (int i = 0; i < (digits.length() - 1) / 3; i++) {
int commaPos = (digits.length() - 3) - (3 * i);
result = result.substring(0, commaPos) + "," + result.substring(commaPos);
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment