List of utility methods to do Float Format
String | formatAmount(float f) 12->12.00 or 11111.1 -> 1,111.10 try { DecimalFormat df = new DecimalFormat("###,###.00"); return df.format(f); } catch (Exception e) { return ""; |
String | formatFloatValue(float value) format Float Value if (value <= 0.0f) { return "0"; String str = String.valueOf(value); Log.d("", " formatFloatValue" + str); int index = str.indexOf('.'); if (index < 0) { return str; ... |
String | formatFloat(float money) format Float return new DecimalFormat("0.00").format(money); |
String | formatAmount(float f) 12->12.00 or 11111.1 -> 1,111.10 try { DecimalFormat df = new DecimalFormat("###,###.00"); return df.format(f); } catch (Exception e) { return ""; |
String | formatSpeed(float data) format Speed return formatSpeed(data, "#0.00"); |
String | formatSpeed(float data, String format) format Speed java.text.DecimalFormat df = new java.text.DecimalFormat(format); if (data < 0) return "0B/s"; if (data < 1000.0) { if (data == (int) data) { df = new java.text.DecimalFormat("#0"); return df.format(data) + "KB/s"; ... |
String | formatSpeedValue(float speed) format Speed Value java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00"); String str = ""; if (speed >= 0 && speed < 1024.0) { df = new java.text.DecimalFormat("#0"); str = df.format(speed) + "KB/s"; } else if (speed >= 1024 && speed < (1024 * 1024.0)) { str = df.format(speed / 1024) + "MB/s"; } else if (speed >= (1024 * 1024) && speed < (1024 * 1024 * 1024.0)) { ... |
Map | formatSpeedWithUnit(float speed) format Speed With Unit java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00"); Map<String, String> map = new HashMap<String, String>(); if (speed < 0) { map.put("speed", "0"); map.put("unit", "KB/s"); return map; if (speed < 1000.0) { ... |
String | formatSpeed(float bytesPerSecond) format Speed float bitsPerSecond = bytesPerSecond * 8; int unit = 1000; if (bitsPerSecond < unit) return bitsPerSecond + " bits/sec"; int exp = (int) (Math.log(bitsPerSecond) / Math.log(unit)); String pre = String.valueOf("kmgtpe".charAt(exp - 1)); return String.format("%.1f %sB/sec", bitsPerSecond / Math.pow(unit, exp), pre); ... |
String | priceFormat(float price, String pattern) price Format String str = "0"; double anotherNan = Double.NaN; if (Double.compare(price, anotherNan) != 0) { DecimalFormat df1 = new DecimalFormat(pattern); str = df1.format(price); } else { DecimalFormat df1 = new DecimalFormat(pattern); str = df1.format(str); ... |