Java BigDecimal Normalize normalizeScale(BigDecimal bigDecimal)

Here you can find the source of normalizeScale(BigDecimal bigDecimal)

Description

Normalizes the scale of bigDecimal to 2 decimal places and RoundingMode#HALF_UP .

License

Apache License

Declaration

public static BigDecimal normalizeScale(BigDecimal bigDecimal) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import static java.math.RoundingMode.HALF_UP;
import java.math.BigDecimal;

public class Main {
    /**/*from   w ww  .  j  a  v a2s .  co  m*/
     * Normalizes the scale of {@code bigDecimal} to 2 decimal places and {@link RoundingMode#HALF_UP}.  All {@link
     * BigDecimal}s within the application should be normalized via this method for consistency.
     */
    public static BigDecimal normalizeScale(BigDecimal bigDecimal) {
        return bigDecimal == null ? null : bigDecimal.setScale(2, HALF_UP);
    }
}

Related

  1. normalize(BigDecimal bigDecimal)
  2. normalize(final BigDecimal dec)
  3. normalizeDecimalValue(BigDecimal bigDecimal, int allowedPrecision)
  4. normalizePrecision(String precision, BigDecimal... decimals)