List of utility methods to do Double Number Format
String | format(Double number) format String num = String.valueOf(number); int index = num.indexOf("."); num = num.substring(0, index); return num; |
String | format(double number, int nums) format return String.format("%." + nums + "f", number); |
double | format(double number, int precision) format int tmp = 1; for (int i = 0; i < precision; i++) { tmp *= 10; int value = (int) Math.round(number * tmp); return (value * 1d) / tmp; |
String | format(double size, String type) format int precision = 0; if (size * 1000 % 10 > 0) { precision = 3; } else if (size * 100 % 10 > 0) { precision = 2; } else if (size * 10 % 10 > 0) { precision = 1; } else { ... |
String | format(double val, int n, int w) format double incr = 0.5; for (int j = n; j > 0; j--) { incr /= 10; val += incr; String s = Double.toString(val); final int n1 = s.indexOf('.'); final int n2 = s.length() - n1 - 1; ... |
String | format(double value, int decimalPlaces) format if (decimalPlaces == 0) { return format(Math.round(value)); final long integerPart = (long) value; double adjust = Math.pow(10, decimalPlaces); long decimalPart = Math.round((Math.abs(value) * adjust) % adjust) + (long) adjust; return format(integerPart) + "." + Long.toString(decimalPart).substring(1); |
double | format(double value, int digits) format if (digits < 0) { return value; return Double.valueOf(String.format("%." + digits + "f", value)); |
String | format(final double power) format return power == 0 ? "%.0f%s" : "%.1f%s"; |
String | formatDouble(double d) Format a double into a string using #DECIMAL_FORMAT . return String.format(DECIMAL_FORMAT, d);
|
String | formatDouble(double d) format Double String s = "" + d; if (s.endsWith(".0")) s = s.substring(0, s.length() - 2); return s; |