Java Utililty Methods BigDecimal Format

List of utility methods to do BigDecimal Format

Description

The list of methods to do BigDecimal Format are organized into topic(s).

Method

StringformatDouble(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();
BigDecimalformatDouble(Double toFormat)
format Double
BigDecimal currency = new BigDecimal(toFormat);
return currency.setScale(SCALE, RoundingMode.DOWN);
doubleformatDouble(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();
doubleformatDoubleNumber(double f)
format Double Number
BigDecimal b = new BigDecimal(f);
return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
doubleformatDoubleValue(int medianAfterTheDecimalPoint, String doubleStringValue)
format Double Value
Double doubleValue = Double.valueOf(doubleStringValue);
return new BigDecimal(doubleValue.doubleValue())
        .setScale(medianAfterTheDecimalPoint, BigDecimal.ROUND_HALF_UP).doubleValue();
Stringformate(BigDecimal amount)
formate
if (amount == null) {
    return "0.00";
return amount.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
StringformatFAAssertRatioWithoutPercent(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);
StringformatFileSize(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";
...
StringformatFloat0(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;
StringformatForPercentage(BigDecimal value)
format For Percentage
String perValue = percentageFormat(value);
return perValue.substring(0, perValue.length() - 1);