Map<String, Object> starMap = new HashMap<>();
NumberFormat fmt = NumberFormat.getPercentInstance();
fmt.setMaximumFractionDigits(2); //保留两位小数
int one = getNumber(); //获取数量
int total = getTotal(); //获取总数
total = total == 0 ? 1 : total; //三目运算符避免除0异常
starMap.put("one",fmt.format((float)one/total)); //百分比
Java-整数相除计算百分比
最新推荐文章于 2024-05-19 16:53:08 发布