List of utility methods to do Decimal Round
double | roundDecimal(double d, int radix) Zaokragla wartosc, do wyznaczonego miejsca po przecinku NumberFormat format = NumberFormat.getInstance(); format.setGroupingUsed(false); format.setMaximumFractionDigits(radix); double res; try { res = format.parse(format.format(d)).doubleValue(); } catch (ParseException e) { res = Double.NaN; ... |
String | roundDecimalPlaces(final double input, final int decimalPlaces) round Decimal Places if (decimalPlaces <= 0) { return NORMAL.format(Math.round(input)); final StringBuilder format = new StringBuilder("###0" + DS); final StringBuilder negativeZero = new StringBuilder("-0" + DS); for (int i = 0; i < decimalPlaces; i++) { format.append('0'); negativeZero.append('0'); ... |
float | roundDecimals(double d, int numOfDec) round Decimals if (numOfDec <= 0) return Math.round(d); String decFormatStr = "#."; for (int i = 0; i < numOfDec; i++) decFormatStr += "#"; DecimalFormat decFormat = new DecimalFormat(decFormatStr); return Float.valueOf(decFormat.format(d)).floatValue(); |
String | roundDistanceFromMeterToKm(final double distanceInMeter) z.B. final double distanceInKilometer = distanceInMeter / KILOMETER_IN_METER; final DecimalFormat format = new DecimalFormat("0.000"); final DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); format.setDecimalFormatSymbols(dfs); return format.format(distanceInKilometer); |
double | roundDouble(double iVal) round Double DecimalFormat df = new DecimalFormat(".0"); String tmp = df.format(iVal); return Double.parseDouble(tmp); |
String | roundDouble(double num, int decimal) round Double String s = "0."; for (int i = 0; i < decimal; i++) { s += "0"; NumberFormat f = new DecimalFormat(s); s = f.format(num); return s; |
String | roundDouble(double numero, int ceros_a_la_derecha) round Double String mascara = "#."; String formateado = ""; String num = ""; for (int i = 0; i < ceros_a_la_derecha; i++) { mascara += "0"; NumberFormat formatter = new DecimalFormat(mascara); num = "" + formatter.format(numero); ... |
double | roundDouble(Double val, int precision) round Double Double dVal = adjDecimalSep(val); BigDecimal bigNumber1 = new BigDecimal(dVal, MathContext.UNLIMITED); return bigNumber1.setScale(precision, BigDecimal.ROUND_CEILING).doubleValue(); |
String | roundedNumber(double inVal) Format a number to a sensible precision int numDigits = 0; if (inVal < 1.0) numDigits = 3; else if (inVal < 10.0) numDigits = 2; else if (inVal < 100.0) numDigits = 1; FORMAT_FLEX.setMaximumFractionDigits(numDigits); ... |
double | RoundFractionalTons(double d) Round Fractional Tons return Double.valueOf(dft.format(d));
|