00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.util;
00023
00024 import org.jetbrains.annotations.NotNull;
00025
00030 public class Formatter {
00031
00035 private Formatter() {
00036 }
00037
00043 @NotNull
00044 public static String formatLong(final long value) {
00045 if (value < 1000000L) {
00046 return Long.toString(value);
00047 }
00048
00049 if (value < 10000000L) {
00050 final long tmp = (value+50000L)/100000L;
00051 return tmp/10+"."+tmp%10+" million";
00052 }
00053
00054 if (value < 1000000000L) {
00055 final long tmp = (value+500000L)/1000000L;
00056 return tmp+" million";
00057 }
00058
00059 if (value < 10000000000L) {
00060 final long tmp = (value+50000000L)/100000000L;
00061 return tmp/10+"."+tmp%10+" billion";
00062 }
00063
00064 final long tmp = (value+500000000L)/1000000000L;
00065 return tmp+" billion";
00066 }
00067
00075 @NotNull
00076 public static String formatFloat(final double value, final int digits) {
00077 final int tmp;
00078 switch (digits) {
00079 case 1:
00080 tmp = (int)Math.round(value*10);
00081 return tmp/10+"."+tmp%10;
00082
00083 case 2:
00084 tmp = (int)Math.round(value*100);
00085 return tmp/100+"."+tmp/10%10+tmp%10;
00086
00087 case 3:
00088 tmp = (int)Math.round(value*1000);
00089 return tmp/1000+"."+tmp/100%10+tmp/10%10+tmp%10;
00090 }
00091
00092 throw new IllegalArgumentException();
00093 }
00094
00095 }