List of usage examples for java.text DecimalFormat format
public final String format(double number)
From source file:Main.java
private static String millisToString(long millis, boolean text) { boolean negative = millis < 0; millis = java.lang.Math.abs(millis); millis /= 1000;//from w ww . j a va 2s. c om int sec = (int) (millis % 60); millis /= 60; int min = (int) (millis % 60); millis /= 60; int hours = (int) millis; String time; DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.US); format.applyPattern("00"); if (text) { if (millis > 0) time = (negative ? "-" : "") + hours + "h" + format.format(min) + "min"; else if (min > 0) time = (negative ? "-" : "") + min + "min"; else time = (negative ? "-" : "") + sec + "s"; } else { if (millis > 0) time = (negative ? "-" : "") + hours + ":" + format.format(min) + ":" + format.format(sec); else time = (negative ? "-" : "") + min + ":" + format.format(sec); } return time; }
From source file:net.nosleep.superanalyzer.util.Misc.java
public static String getFormattedBitrate(double bitrate) { DecimalFormat decimalFormat = new DecimalFormat("0.0"); return decimalFormat.format(bitrate) + " kbps"; }
From source file:de.awtools.basic.AWTools.java
/** * Wandelt einen double Wert in einen String anhand des angegebenen Patterns. * Siehe zu diesem Thema auch im Java-Tutorial bzw. API. * * <p>//from w ww .j av a2 s. c o m * Apply the given pattern to this Format object. A pattern is a short-hand * specification for the various formatting properties. These properties can * also be changed individually through the various setter methods. There * is no limit to integer digits set by this routine, since that is the * typical end-user desire; use setMaximumInteger if you want to set a * real value. For negative numbers, use a second pattern, separated by a semicolon * </p> * <p> * Example "#,#00.0#" -> 1,234.56 * This means a minimum of 2 integer digits, 1 fraction digit, and a maximum * of 2 fraction digits. * </p> * <p> * Example: "#,#00.0#;(#,#00.0#)" for negatives in parentheses. * In negative patterns, the minimum and maximum counts are ignored; these * are presumed to be set in the positive pattern. * </p> * * @param value Der zu konvertierende Wert. * @param pattern Das zu verwendende Pattern. * @param locale Das zu verwendende Locale. * @return Formatiert einen <code>double</code>. */ public static String toString(final double value, String pattern, final Locale locale) { NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyPattern(pattern); return df.format(value); }
From source file:gob.dp.simco.comun.FunctionUtil.java
public static String formateaDecimal(double numero) { if (numero > 0) { Locale locale = new Locale("en", "UK"); String pattern = "###,###.##"; DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale); decimalFormat.applyPattern(pattern); String format = decimalFormat.format(numero); return format; }//from ww w . j a v a 2 s .com return null; }
From source file:jp.co.opentone.bsol.linkbinder.util.ValueFormatter.java
/** * ?(9,999,999)???./*from ww w.j ava 2 s .com*/ * @param number * @return */ public static String formatNumber(int number) { DecimalFormat formatter = new DecimalFormat(FORMAT_NUMBER); return formatter.format(number); }
From source file:com.alibaba.otter.manager.web.common.NumberFormatUtil.java
public static String formatFileSize(Number data) { if (data == null) { return null; }/* w w w .j a va 2s. co m*/ long size = data.longValue(); if (size > TB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / TB_SIZE) + " TB"; } else if (size > GB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / GB_SIZE) + " GB"; } else if (size > MB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / MB_SIZE) + " MB"; } else if (size > KB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / KB_SIZE) + " KB"; } else { DecimalFormat format = new DecimalFormat(PATTERN); return format.format(size) + " B"; } }
From source file:com.sec.ose.osi.sdk.protexsdk.project.ProjectEntForReportFactory.java
private static String calculateOriginPendingRatio(int totalFileNum, int originPendingFileNum) { DecimalFormat df = new DecimalFormat("##0.00%"); return df.format((double) originPendingFileNum / (double) totalFileNum); }
From source file:Main.java
public static double calculateBMR(int sex, double weight, double height, int age) { double result = 0.0; DecimalFormat format = new DecimalFormat("0.00"); if (sex == UserSexMale) { result = 655 + (9.6 * weight) + (1.8 * height) - (4.7 * age); } else {/*from w w w. j a v a 2 s . c o m*/ result = 66 + (13.8 * weight) + (5.0 * height) - (6.8 * age); } return Double.valueOf(format.format(result).toString()); }
From source file:Main.java
/** * /* w w w.jav a2 s. co m*/ * @Title: formatCacheMeasure: format files' measure * @Description: formatCacheMeasure * @param @param path * @param @return * @return String * @throws @param path * @throws @return */ public static String formatCacheMeasure(String path) { String measure; DecimalFormat df = new DecimalFormat(CACHE_MEASURE_FORMATE); getCacheMeasure(path); if (mCacheMeasure == 0.0) { mCacheMeasure = 0; return null; } else if (mCacheMeasure < CACHESIZE1) { measure = df.format((double) mCacheMeasure / CACHESIZE0) + "K"; } else if (mCacheMeasure < 1073741824) { measure = df.format((double) mCacheMeasure / CACHESIZE1) + "M"; } else { measure = df.format((double) mCacheMeasure / CACHESIZE2) + "G"; } mCacheMeasure = 0; return measure; }
From source file:jp.co.nemuzuka.utils.ConvertUtils.java
/** * NumberString?./* w w w .j ava 2 s .co m*/ * ??null??????? * @param val ? * @param df * @return */ public static String toString(Number val, DecimalFormat df) { if (val == null) { return ""; } return df.format(val); }