Java BigDecimal getPercent(BigDecimal numerator, BigDecimal denominator)

Here you can find the source of getPercent(BigDecimal numerator, BigDecimal denominator)

Description

get Percent

License

Open Source License

Declaration

public static BigDecimal getPercent(BigDecimal numerator, BigDecimal denominator) 

Method Source Code

//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;
    }
}

Related

  1. getMean(final BigDecimal... vals)
  2. getMicroSec(BigDecimal hours)
  3. getNumberAsBigDecimal(Number value)
  4. getNumberOfDecimalPlaces(BigDecimal bigDecimal)
  5. getParamBigDecimal(Map paramMap, String paramName)
  6. getPercentage(BigDecimal amount, BigDecimal percent)
  7. getPercentageValue(BigDecimal price, double amount)
  8. getProfit(BigDecimal ask, BigDecimal bid, BigDecimal fee)
  9. getProzentWert(BigDecimal zahl, BigDecimal prozentsatz, int nachkommastellen)