get Percentage from two double value - Java java.lang

Java examples for java.lang:double

Description

get Percentage from two double value

Demo Code


//package com.java2s;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] argv) throws Exception {
        double part = 2.45678;
        double whole = 2.45678;
        System.out.println(getPercentage(part, whole));
    }//from  w  w w  .j  a  v a  2  s.c om

    public static BigDecimal getPercentage(double part, double whole) {
        return new BigDecimal(part * 100 / whole);
    }
}

Related Tutorials