Botre Posted March 10, 2015 Share Posted March 10, 2015 (edited) LAST UPDATE: MARCH 10, 2015 package org.bjornkrols.math.ratio; import java.math.BigDecimal; /** * @author Bjorn Krols (Botre) * @version 0.0 * @since March 10, 2015 */ public final class Ratio { private Ratio() { // This class should never be instantiated. // Do not delete or make accessible. } /* * INT */ public static int percentage(int part, int whole) { return part * 100 / whole ; } /* * LONG */ public static long percentage(long part, long whole) { return part * 100 / whole ; } /* * FLOAT */ public static float percentage(float part, float whole) { return part * 100 / whole ; } public static float decimal(float part, float whole) { return part / whole ; } /* * DOUBLE */ public static double percentage(double part, double whole) { return part * 100 / whole ; } public static double decimal(double part, double whole) { return part / whole ; } /* * BIG DECIMAL */ private static final BigDecimal HUNDRED = new BigDecimal(100); public static BigDecimal percentage(BigDecimal part, BigDecimal whole) { part.multiply(HUNDRED).divide(whole); } public static BigDecimal decimal(BigDecimal part, BigDecimal whole) { return part.divide(whole); } } Edited March 10, 2015 by Botre 1 Quote Link to comment Share on other sites More sharing options...