Calculate percentage, based on total and current value. - Android java.lang

Android examples for java.lang:Math

Description

Calculate percentage, based on total and current value.

Demo Code


//package com.java2s;

public class Main {
    /**//from  ww w . j av  a 2  s .  c o  m
     * Calculate percentage, based on total and current value.
     * 
     * <pre>
     * computePercent(8508,9689)          =87
     * </pre>
     * @param current
     * @param total
     * @return
     */
    public static int computePercent(int current, int total) {
        int percent = 0;
        if (total > 0)
            percent = current * 100 / total;
        return percent;
    }
}

Related Tutorials