Advertisement
Guest User

Untitled

a guest
May 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public static String formatDouble(final double amount) {
  2. if (amount >= 1.0E33) {
  3. return String.format("%.2fD", amount / 1.0E33);
  4. }
  5. if (amount >= 1.0E30) {
  6. return String.format("%.2fN", amount / 1.0E30);
  7. }
  8. if (amount >= 1.0E27) {
  9. return String.format("%.2fO", amount / 1.0E27);
  10. }
  11. if (amount >= 1.0E24) {
  12. return String.format("%.2fSS", amount / 1.0E24);
  13. }
  14. if (amount >= 1.0E21) {
  15. return String.format("%.2fS", amount / 1.0E21);
  16. }
  17. if (amount >= 1.0E18) {
  18. return String.format("%.2fQQ", amount / 1.0E18);
  19. }
  20. if (amount >= 1.0E15) {
  21. return String.format("%.2fQ", amount / 1.0E15);
  22. }
  23. if (amount >= 1.0E12) {
  24. return String.format("%.2fT", amount / 1.0E12);
  25. }
  26. if (amount >= 1.0E9) {
  27. return String.format("%.2fB", amount / 1.0E9);
  28. }
  29. if (amount >= 1000000.0) {
  30. return String.format("%.2fM", amount / 1000000.0);
  31. }
  32. if (amount >= 1000.0) {
  33. return String.format("%.2fK", amount / 1000.0);
  34. }
  35. final DecimalFormat df = new DecimalFormat("#.##");
  36. df.setDecimalSeparatorAlwaysShown(false);
  37. return df.format(amount);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement