Created
April 23, 2014 03:33
-
-
Save yelinaung/11202002 to your computer and use it in GitHub Desktop.
Insert comma on every three digits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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