Here you can find the source of getRoundedAmt(BigDecimal amtBeforeRnd)
Parameter | Description |
---|---|
notRoundAmt | Amount before rounded |
public static BigDecimal getRoundedAmt(BigDecimal amtBeforeRnd)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { private static final BigDecimal increment = new BigDecimal("0.05"); /**//from w w w. j a v a 2s . c o m * Round the amount to the nearest 5 cents<br> * For example:<br> * 0.12 ---> 0.10<br> * 0.13 ---> 0.15<br> * 0.17 ---> 0.15<br> * 0.18 ---> 0.20 * * @param notRoundAmt * Amount before rounded * @return Amount rounded to the nearest 5 cents */ public static BigDecimal getRoundedAmt(BigDecimal amtBeforeRnd) { BigDecimal divided = amtBeforeRnd.divide(increment, 0, BigDecimal.ROUND_HALF_UP); BigDecimal roundedAmt = divided.multiply(increment); return roundedAmt; } }