Here you can find the source of getPercent(BigDecimal numerator, BigDecimal denominator)
public static BigDecimal getPercent(BigDecimal numerator, BigDecimal denominator)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; public class Main { public static final BigDecimal HUNDRED = new BigDecimal(100); public static BigDecimal getPercent(BigDecimal numerator, BigDecimal denominator) { if (denominator == null || numerator == null || denominator.compareTo(BigDecimal.ZERO) == 0) { return BigDecimal.ZERO; }/*from w w w . j a v a 2 s.co m*/ return numerator.divide(denominator, 4, BigDecimal.ROUND_HALF_EVEN).multiply(HUNDRED).setScale(2, BigDecimal.ROUND_HALF_EVEN); } public static double getPercent(double numerator, double denominator) { if (denominator == 0) { return 0; } return (numerator / denominator) * 100; } }