List of utility methods to do Decimal Round
double | roundNumDecimals(double d, int num) round Num Decimals StringBuilder format = new StringBuilder("#."); for (int i = 0; i < num; i++) { format.append("#"); DecimalFormat f = new DecimalFormat(format.toString()); return Double.valueOf(f.format(d)); |
double | roundOffToTwoDecimal(double value) round Off To Two Decimal DecimalFormat df = new DecimalFormat("0.00"); return new Double(df.format(value)); |
double | roundThreeDecimals(double d) round Three Decimals if (Double.isInfinite(d) || Double.isNaN(d)) { return d; DecimalFormat threeDForm = new DecimalFormat("#.###"); return Double.valueOf(threeDForm.format(d)); |
Double | roundTwoDecimals(double d) This method rounds up a decimal number up to N decimals. DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(d)); |
double | roundTwoDecimals(double d) round Two Decimals try { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(d)); } catch (NumberFormatException e) { return d; |
Double | roundTwoDecimals(Double d) Round up to two decimals DecimalFormat twoDForm = new DecimalFormat("###.##"); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); twoDForm.setDecimalFormatSymbols(dfs); return Double.valueOf(twoDForm.format(d)); |
String | roundTwoDecimals(double d) round Two Decimals DecimalFormat twoDForm = new DecimalFormat("#.##"); return twoDForm.format(d); |
String | to_decimal(double v) Returns a decimal representation of a double (no scientific notation used). final NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setMinimumFractionDigits(2); nf.setMaximumFractionDigits(4); return nf.format(v); |
String | toLimitDecimalFloatStr(double number, int newScale) to Limit Decimal Float Str NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(newScale);
return nf.format(number);
|
String | toNumber(Double value, Double defaultValue) Remove decimals String number = ""; if (value == null) { value = defaultValue; if (value != null) { NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(0); ... |