compute Exact Percent - Android java.lang

Android examples for java.lang:Math

Description

compute Exact Percent

Demo Code


//package com.java2s;

public class Main {
    /**/*w  w w .j  av  a2 s  .  c o  m*/
     * <pre>
     * computeExactPercent(135,1036)      =13.03088803088803
     * </pre>
     * @param current -value out of total
     * @param total -total
     * @return double -exact percentage
     */
    public static double computeExactPercent(int current, int total) {
        double percent = 0;
        double t = total;
        double c = current;
        if (total > 0)
            percent = c * 100 / t;
        return percent;
    }
}

Related Tutorials