/**
-
@author zjx
-
@Description: 百分比
*/
public class MyMath {
private MyMath() {}
/**
- @param d1:分子;
- @param zs:分母;
- @param dot:要保留的小数
- @Description: 计算百分
*/
public static double percentage(double d1, double zs, int dot) {
double bs = Math.pow(10.0, toDouble(dot + 2, 0.0));
double cs = Math.pow(10.0, toDouble(dot, 0.0));
double num = 0.0;
if (zs > 0) {
num = Math.floor(d1 * bs / zs) / cs;
}
return num;
}
/**
- @param d1:分子;
- @param zs:分母;
- @param dot:要保留的小数
- @return
- @Description: 计算百分比
*/
public static double percentage(int d1, int zs, int dot) {
double bs = Math.pow(10.0, toDouble(dot + 2, 0.0));
double cs = Math.pow(10.0, toDouble(dot, 0.0));
double num = 0.0;
if (zs > 0) {
num = Math.floor(d1 * bs / zs) / cs;
}
return num;
}
private static Double toDouble(Object value, Double defaultValue) {
if (null == value) {
return defaultValue;
}
return Double.parseDouble(value.toString());
}