Last active
November 9, 2015 01:37
-
-
Save ztrehagem/17dfcc91c2abd1cd03ef to your computer and use it in GitHub Desktop.
convert int into money format string
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
public static String makeMoneyFormat(int money) { | |
StringBuilder str = new StringBuilder(""); | |
StringBuilder target = new StringBuilder(String.valueOf(money % 1000)); | |
while ((money /= 1000) > 0) { | |
while (target.length() < 3) | |
target.insert(0, "0"); | |
str.insert(0, target); | |
str.insert(0, ","); | |
target.setLength(0); | |
target.append(String.valueOf(money % 1000)); | |
} | |
str.insert(0, target); | |
return str.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment