use of java.text.DecimalFormat in project otter by alibaba.
the class NumberFormatUtil method formatDelay.
public static String formatDelay(Number data) {
if (data == null) {
return StringUtils.EMPTY;
}
long t = data.longValue();
if (t < 0) {
return String.valueOf(t);
}
int hour = 0;
int minute = 0;
while (t >= 60 * 60 * 1000) {
hour++;
t -= 60 * 60 * 1000;
}
while (t >= 60 * 1000) {
minute++;
t -= 60 * 1000;
}
List<String> result = new ArrayList<String>();
if (hour > 0) {
result.add(hour + " h");
}
if (minute > 0) {
result.add(minute + " m");
}
if (t > 0) {
DecimalFormat format = new DecimalFormat(PATTERN);
result.add(format.format((t * 1.0) / 1000) + " s");
}
if (result.size() == 0) {
return "0";
}
return StringUtils.join(result, " ");
}
use of java.text.DecimalFormat in project StylishMusicPlayer by ryanhoo.
the class FileUtils method readableFileSize.
/**
* http://stackoverflow.com/a/5599842/2290191
*
* @param size Original file size in byte
* @return Readable file size in formats
*/
public static String readableFileSize(long size) {
if (size <= 0)
return "0";
final String[] units = new String[] { "b", "kb", "M", "G", "T" };
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
return new DecimalFormat("#,##0.##").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
use of java.text.DecimalFormat in project platform_frameworks_base by android.
the class VectorDrawablePerformance method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView scrollView = new ScrollView(this);
GridLayout container = new GridLayout(this);
scrollView.addView(container);
container.setColumnCount(4);
Resources res = this.getResources();
container.setBackgroundColor(0xFF888888);
VectorDrawable[] d = new VectorDrawable[icon.length];
long time = android.os.SystemClock.elapsedRealtimeNanos();
for (int i = 0; i < icon.length; i++) {
d[i] = create(res, icon[i]);
}
time = android.os.SystemClock.elapsedRealtimeNanos() - time;
TextView t = new TextView(this);
DecimalFormat df = new DecimalFormat("#.##");
t.setText("avgL=" + df.format(time / (icon.length * 1000000.)) + " ms");
container.addView(t);
time = android.os.SystemClock.elapsedRealtimeNanos();
for (int i = 0; i < icon.length; i++) {
Button button = new Button(this);
button.setWidth(200);
button.setBackgroundResource(icon[i]);
container.addView(button);
}
setContentView(scrollView);
time = android.os.SystemClock.elapsedRealtimeNanos() - time;
t = new TextView(this);
t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms");
container.addView(t);
}
use of java.text.DecimalFormat in project platform_frameworks_base by android.
the class AnimatedVectorDrawableDupPerf method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView scrollView = new ScrollView(this);
GridLayout container = new GridLayout(this);
scrollView.addView(container);
container.setColumnCount(5);
Resources res = this.getResources();
container.setBackgroundColor(0xFF888888);
AnimatedVectorDrawable[] d = new AnimatedVectorDrawable[icon.length];
long time = android.os.SystemClock.elapsedRealtimeNanos();
for (int i = 0; i < icon.length; i++) {
d[i] = create(res, icon[i]);
}
time = android.os.SystemClock.elapsedRealtimeNanos() - time;
TextView t = new TextView(this);
DecimalFormat df = new DecimalFormat("#.##");
t.setText("avgL=" + df.format(time / (icon.length * 1000000.)) + " ms");
container.addView(t);
time = android.os.SystemClock.elapsedRealtimeNanos();
for (int i = 0; i < icon.length; i++) {
Button button = new Button(this);
button.setWidth(200);
button.setBackgroundResource(icon[i]);
container.addView(button);
}
setContentView(scrollView);
time = android.os.SystemClock.elapsedRealtimeNanos() - time;
t = new TextView(this);
t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms");
container.addView(t);
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_parse_minusInfinityBigDecimalFalse.
public void test_parse_minusInfinityBigDecimalFalse() {
// Regression test for HARMONY-106
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance();
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
Number number = format.parse("-" + symbols.getInfinity(), new ParsePosition(0));
assertTrue(number instanceof Double);
assertTrue(Double.isInfinite(number.doubleValue()));
}
Aggregations