Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String formatDouble(final double amount) {
- if (amount >= 1.0E33) {
- return String.format("%.2fD", amount / 1.0E33);
- }
- if (amount >= 1.0E30) {
- return String.format("%.2fN", amount / 1.0E30);
- }
- if (amount >= 1.0E27) {
- return String.format("%.2fO", amount / 1.0E27);
- }
- if (amount >= 1.0E24) {
- return String.format("%.2fSS", amount / 1.0E24);
- }
- if (amount >= 1.0E21) {
- return String.format("%.2fS", amount / 1.0E21);
- }
- if (amount >= 1.0E18) {
- return String.format("%.2fQQ", amount / 1.0E18);
- }
- if (amount >= 1.0E15) {
- return String.format("%.2fQ", amount / 1.0E15);
- }
- if (amount >= 1.0E12) {
- return String.format("%.2fT", amount / 1.0E12);
- }
- if (amount >= 1.0E9) {
- return String.format("%.2fB", amount / 1.0E9);
- }
- if (amount >= 1000000.0) {
- return String.format("%.2fM", amount / 1000000.0);
- }
- if (amount >= 1000.0) {
- return String.format("%.2fK", amount / 1000.0);
- }
- final DecimalFormat df = new DecimalFormat("#.##");
- df.setDecimalSeparatorAlwaysShown(false);
- return df.format(amount);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement