Compute percentage for bigdecimals

I don’t think there is an API for that (I never needed it).
Your solution seams good to me, maybe you just add the constant ONE_HUNDRED:

public static final BigDecimal ONE_HUNDRED = new BigDecimal(100);

public static BigDecimal percentage(BigDecimal base, BigDecimal pct){
    return base.multiply(pct).divide(ONE_HUNDRED);
}

probably not that much gain, only if called very often

eventually put it in some Util class…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)