Created
November 8, 2016 11:34
-
-
Save jessejohnson/98ffc6bf8ea8f1073975ed6e7c57ab7c to your computer and use it in GitHub Desktop.
format large numbers like on Twitter, etc.
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 formatLargeInteger(int largeInt){ | |
if(largeInt < 10000){ | |
//ie. 0 - 9,999 | |
return String.valueOf(largeInt); | |
}else if(largeInt >= 10000 && largeInt < 1000000){ | |
//ie. 10,000 - 999,999 | |
String s = String.valueOf(largeInt); | |
return s.substring(0, s.length() - 3) + "K"; //10K - 999K | |
}else { | |
//ie. 1,000,000 - inf | |
String s = String.valueOf(largeInt); | |
return s.substring(0, s.length() - 6) + "M"; //1M - infM | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment