Search in sources :

Example 26 with DecimalFormat

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, " ");
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList)

Example 27 with DecimalFormat

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];
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 28 with DecimalFormat

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);
}
Also used : GridLayout(android.widget.GridLayout) ScrollView(android.widget.ScrollView) Button(android.widget.Button) DecimalFormat(java.text.DecimalFormat) TextView(android.widget.TextView) Resources(android.content.res.Resources) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 29 with DecimalFormat

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);
}
Also used : GridLayout(android.widget.GridLayout) ScrollView(android.widget.ScrollView) Button(android.widget.Button) DecimalFormat(java.text.DecimalFormat) TextView(android.widget.TextView) Resources(android.content.res.Resources) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 30 with DecimalFormat

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()));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) ParsePosition(java.text.ParsePosition)

Aggregations

DecimalFormat (java.text.DecimalFormat)823 DecimalFormatSymbols (java.text.DecimalFormatSymbols)94 NumberFormat (java.text.NumberFormat)93 IOException (java.io.IOException)48 BigDecimal (java.math.BigDecimal)47 ArrayList (java.util.ArrayList)44 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)33 ParseException (java.text.ParseException)31 Test (org.junit.Test)31 File (java.io.File)29 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)29 Support_DecimalFormat (tests.support.Support_DecimalFormat)28 Date (java.util.Date)25 SimpleDateFormat (java.text.SimpleDateFormat)24 HashMap (java.util.HashMap)24 Locale (java.util.Locale)22 PrintWriter (java.io.PrintWriter)20 UsageVO (com.cloud.usage.UsageVO)19 List (java.util.List)18 JFreeChart (org.jfree.chart.JFreeChart)18