Skip to content

Instantly share code, notes, and snippets.

@ztrehagem
Last active November 9, 2015 01:37
Show Gist options
  • Save ztrehagem/17dfcc91c2abd1cd03ef to your computer and use it in GitHub Desktop.
Save ztrehagem/17dfcc91c2abd1cd03ef to your computer and use it in GitHub Desktop.
convert int into money format string
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