List of utility methods to do BigDecimal Format
String | formatDouble(Double someDouble, int digitsToTheRightOfDecimal) Formats a double as a string with the specified number of fractional digits. BigDecimal bigDecimal = BigDecimal.valueOf(someDouble);
bigDecimal = bigDecimal.setScale(digitsToTheRightOfDecimal, RoundingMode.HALF_UP);
return bigDecimal.toPlainString();
|
BigDecimal | formatDouble(Double toFormat) format Double BigDecimal currency = new BigDecimal(toFormat); return currency.setScale(SCALE, RoundingMode.DOWN); |
double | formatDouble(double value, int decimalPlaces) format Double if (decimalPlaces < 0) { throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(value); bd = bd.setScale(decimalPlaces, RoundingMode.HALF_UP); return bd.doubleValue(); |
double | formatDoubleNumber(double f) format Double Number BigDecimal b = new BigDecimal(f); return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
double | formatDoubleValue(int medianAfterTheDecimalPoint, String doubleStringValue) format Double Value Double doubleValue = Double.valueOf(doubleStringValue); return new BigDecimal(doubleValue.doubleValue()) .setScale(medianAfterTheDecimalPoint, BigDecimal.ROUND_HALF_UP).doubleValue(); |
String | formate(BigDecimal amount) formate if (amount == null) { return "0.00"; return amount.setScale(2, BigDecimal.ROUND_HALF_UP).toString(); |
String | formatFAAssertRatioWithoutPercent(BigDecimal value) format FA Assert Ratio Without Percent DecimalFormat decimalFormat = new DecimalFormat(FA_ASSERT_RATIO_FORMAT); decimalFormat.setRoundingMode(RoundingMode.DOWN); return decimalFormat.format(value).substring(0, decimalFormat.format(value).length() - 1); |
String | formatFileSize(double size) format File Size double kiloByte = size / 1024; if (kiloByte < 1) { return size + "Byte(s)"; double megaByte = kiloByte / 1024; if (megaByte < 1) { BigDecimal result1 = new BigDecimal(Double.toString(kiloByte)); return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB"; ... |
String | formatFloat0(String value, int n) format Float if (null != value && value.contains(".")) { if (isNumeric(value)) { try { BigDecimal decimal = new BigDecimal(value); BigDecimal setScale = decimal.setScale(n, BigDecimal.ROUND_HALF_DOWN); return setScale.toPlainString(); } catch (Exception e) { return value; |
String | formatForPercentage(BigDecimal value) format For Percentage String perValue = percentageFormat(value);
return perValue.substring(0, perValue.length() - 1);
|