List of utility methods to do Double Number Format
double | formatDouble(double d) format Double return (double) Math.round(d * 100) / 100; |
String | formatDouble(double d, int n) format Double int x = (int) Math.pow(10, n); return Double.toString((double) (((int) (x * d)) / (double) x)); |
String | formatDouble(double d, int n) Formats a double to a given number of digits past the decimal point and cuts the tailing zeroes String s = String.format("%." + n + "f", d); int i = s.length() - 1; while (s.charAt(i) == '0') { s = s.substring(0, i); i--; if (s.charAt(i) == '.') s = s.substring(0, i); ... |
String | formatDouble(double d, int n, String pad) format Double String s = Double.toString(d); int len = s.length(); if (len > n) return s.substring(0, n); for (; len < n; len++) s = s + pad; return s; |
String | formatDouble(double d, int precision) Returns a string of the double with the specified floating point precision with zeroes added if required to achieve the precision. double 10.03 with precision 4 will result in 10.0300 double 2.123456 with precision 4 will result in 2.1234 String result = String.valueOf(d); int floatingPoint = result.indexOf('.'); int addZeroes = -(result.length() - (floatingPoint + 1) - precision); if (addZeroes < 0) { return result.substring(0, floatingPoint + 1 + precision); } else { for (int i = 0; i < addZeroes; i++) { result = result + "0"; ... |
String | formatDouble(double inDouble, boolean inComma, int inCommaPos) This function is to format the double value. int dp = 0; long tens = 1; long tempInt = (long) (fixDouble(inDouble * tens)); while (fixDouble(inDouble * tens) != tempInt) { dp++; tens = tens * 10; tempInt = (long) (fixDouble(inDouble * tens)); return formatDouble(inDouble, dp, inComma, inCommaPos); |
String | formatDouble(double num, int width, int precision) format Double return formatReal(String.valueOf(num), width, precision);
|
String | FormatDouble(double p_value, int p_numberOfDecimalPlaces) Format Double String t_valueString = Double.toString(p_value); if (t_valueString.contains(".")) { int t_decimalIndex = t_valueString.indexOf("."); if ((t_valueString.length() - (t_decimalIndex + 1)) > p_numberOfDecimalPlaces) { t_valueString = t_valueString.substring(0, (t_decimalIndex + (p_numberOfDecimalPlaces + 1))); return t_valueString; ... |
String | formatDouble(double source, int decimals, int precision) format Double StringBuffer target = new StringBuffer(); int scale = (Math.abs(source) >= 1.0) ? decimals : precision; if (tooManyDigitsUsed(source, scale) || tooCloseToRound(source, scale)) { formatDoublePrecise(source, decimals, precision, target); } else { formatDoubleFast(source, decimals, precision, target); return target.toString(); ... |
String | formatDouble(double v, int decimalPlaces) format Double String ret = String.valueOf(v); int i = ret.indexOf("."); if (ret.length() > i + decimalPlaces + 1) ret = ret.substring(0, i + decimalPlaces + 1); else ret += "0000000000".substring(0, i + decimalPlaces + 1 - ret.length()); return ret; |