List of usage examples for java.text DecimalFormat DecimalFormat
public DecimalFormat(String pattern)
From source file:Main.java
/** * According station to get frequency string * * @param station for 100KZ, range 875-1080 * * @return string like 87.5//from w ww .ja v a 2 s .c o m */ public static String formatStation(int station) { float frequency = (float) station / CONVERT_RATE; DecimalFormat decimalFormat = new DecimalFormat("0.0"); return decimalFormat.format(frequency); }
From source file:Main.java
private static double FormetFileSize(long fileS, int sizeType) { DecimalFormat df = new DecimalFormat("#.00"); double fileSizeLong = 0; switch (sizeType) { case SIZETYPE_B: fileSizeLong = Double.valueOf(df.format((double) fileS)); break;// ww w. j av a 2s . c o m case SIZETYPE_KB: fileSizeLong = Double.valueOf(df.format((double) fileS / 1024)); break; case SIZETYPE_MB: fileSizeLong = Double.valueOf(df.format((double) fileS / 1048576)); break; case SIZETYPE_GB: fileSizeLong = Double.valueOf(df.format((double) fileS / 1073741824)); break; default: break; } return fileSizeLong; }
From source file:Main.java
public static String readableFileSize(long size) { if (size <= 0) return "0"; final String[] units = new String[] { "Byte", "KB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; }
From source file:Main.java
public static String getFileSize(long fileSize) { int freeUnit; for (freeUnit = 0; fileSize >= 100; freeUnit++) { fileSize /= 1024;/*from w w w . j a va 2 s . c o m*/ } DecimalFormat decFormat = new DecimalFormat("0.0"); String doubleString = decFormat.format(fileSize); StringBuffer buffer = new StringBuffer(); buffer.append(doubleString); switch (freeUnit) { case 0: buffer.append("B"); break; case 1: buffer.append("KB"); break; case 2: buffer.append("MB"); break; case 3: buffer.append("GB"); break; case 4: buffer.append("TB"); break; default: buffer.append("err"); break; } return buffer.toString(); }
From source file:Main.java
public static String formatBalance(BigDecimal balance, String curr, boolean round, DecimalFormat format) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator(','); dfs.setGroupingSeparator(' '); DecimalFormat currency = format; if (currency == null) { if (!round) { currency = new DecimalFormat("#,##0.00 "); } else {//from w ww . ja v a2 s. c o m currency = new DecimalFormat("#,##0 "); } } currency.setDecimalFormatSymbols(dfs); return currency.format(balance.doubleValue()) + curr; }
From source file:br.com.pontocontrol.controleponto.ExtObject.java
protected static String formatNumber(String pattern, Object arg) { return new DecimalFormat(pattern).format(arg); }
From source file:jp.co.opentone.bsol.framework.core.util.ConvertUtil.java
/** * 3???.// ww w . jav a 2 s . c o m * @param value * @return 3? */ public static String formatNumber(Integer value) { DecimalFormat f = new DecimalFormat("#,##0"); return value == null ? "" : f.format(value).toString(); }
From source file:Main.java
public static Double getBitmapsize(Bitmap bitmap, int sizeType) { long fileS = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { // fileS = bitmap.getByteCount(); Bitmap.Config config = bitmap.getConfig(); if (config == Bitmap.Config.RGB_565 || config == Bitmap.Config.ARGB_4444) { fileS = bitmap.getWidth() * bitmap.getHeight() * 2; } else if (config == Bitmap.Config.ALPHA_8) { fileS = bitmap.getWidth() * bitmap.getHeight(); } else if (config == Bitmap.Config.ARGB_8888) { fileS = bitmap.getWidth() * bitmap.getHeight() * 4; }// w w w . j a v a 2s . c om } else { fileS = bitmap.getRowBytes() * bitmap.getHeight();// Pre HC-MR1 } DecimalFormat df = new DecimalFormat("#.00"); double fileSizeLong = 0; switch (sizeType) { case SIZETYPE_B: fileSizeLong = Double.valueOf(df.format((double) fileS)); break; case SIZETYPE_KB: fileSizeLong = Double.valueOf(df.format((double) fileS / 1024)); break; case SIZETYPE_MB: fileSizeLong = Double.valueOf(df.format((double) fileS / 1048576)); break; case SIZETYPE_GB: fileSizeLong = Double.valueOf(df.format((double) fileS / 1073741824)); break; default: break; } return fileSizeLong; }
From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Mp3Stats.java
public static void genStatistics(Mp3Db db, XmlElement node) { DecimalFormat df = new DecimalFormat("#,###"); node.add(Html.p(code("Komponisten: " + df.format(db.composers.table.size())))); List<Media> ml = db.getMedia(); int cdc = 0;// ww w . j a v a2s .c om for (Media m : ml) { String mc = m.get(Media.MEDIACOUNT); if (StringUtils.isBlank(mc) == true) { ++cdc; continue; } try { cdc += NumberUtils.createInteger(mc); } catch (NumberFormatException ex) { ++cdc; } } int tcest = 36000; node.add(Html.p(code("Medien: " + df.format(ml.size()) + ", single: " + df.format(cdc)))); node.add(Html.p(code("Titel: " + df.format(db.title.table.size())))); node.add(Html.p(code("<i>Only Parts with trackinfo</i>:"))); double factor = (double) tcest / (double) db.tracks.table.size(); node.add(Html.p(code("Tracks: " + df.format(db.tracks.table.size())))); long timesec = 0; long sizebytes = 0; for (String[] td : db.tracks.table) { Track track = new Track(db, td); timesec += track.getTime(); sizebytes += track.getSize(); } long esttimesec = (long) (factor * timesec); SimpleDateFormat sd = new SimpleDateFormat("MM-dd HH:mm:ss"); String dur = sd.format(new Date(timesec * 1000)); String esdur = sd.format(new Date(esttimesec * 1000)); String size = df.format(sizebytes); node.add(Html.p(code("Total time: " + dur + ", " + df.format((int) (timesec / 3600)) + " hours"))); node.add(Html.p(code("Total size: " + size + " (Parts)"))); node.add(Html.p(code("Orchester: " + df.format(db.orchesters.table.size())))); node.add(Html.p(code("Intepreten: " + df.format(db.interprets.table.size())))); }
From source file:Main.java
public static String percent(double value1, double value2, int decimalPointAfterLength, boolean replaceWithZero, boolean removePercent) { StringBuffer buffString = new StringBuffer(); buffString.append("#"); if (decimalPointAfterLength > 0) { buffString.append("."); }/*from ww w . ja v a 2 s .c om*/ for (int w = 0; w < decimalPointAfterLength; w++) { buffString.append(replaceWithZero ? "0" : "#"); } buffString.append("%"); if (buffString.length() > 0) { String result = new DecimalFormat(buffString.toString()).format(value1 / value2); if (removePercent && result.length() > 0) { result = result.substring(0, result.length() - 1); } return result; } else { return null; } }