-
-
Save slashnhax/c986acebcf7d25e3bff5 to your computer and use it in GitHub Desktop.
toPhrase
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 toPhrase(long l, NumberFormat format){ | |
String res = ""; | |
double d = l; | |
while(d > 1000){ | |
if (d >= Math.pow(10, 12)) { | |
res = "T" + res; | |
} else if(d >= Math.pow(10, 9)){ | |
res = "B" + res; | |
d /= Math.pow(10, 9); | |
} else if (d >= Math.pow(10, 6)){ | |
res = "M" + res; | |
d /= Math.pow(10, 6); | |
} else if (d >= Math.pow(10, 3)){ | |
res = "K" + res; | |
d /= Math.pow(10, 3); | |
} | |
} | |
if(format == null) | |
res = d + res; | |
else | |
res = format.format(d) + res; | |
return res; | |
} | |
public static void main(String[] args) { | |
System.out.println(toPhrase(12345678912l, null)); | |
System.out.println(toPhrase(12345678912l, DecimalFormat.getCurrencyInstance())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment