private long getPercent(long count, long total) {
if(total==0){
return 0;
}
BigDecimal currentCount = new BigDecimal(count);
BigDecimal totalCount = new BigDecimal(total);
BigDecimal divide = currentCount.divide(totalCount,2, BigDecimal.ROUND_HALF_UP);
return divide.multiply(new BigDecimal(100)).longValue();
}
long类型的两个值计算百分比
最新推荐文章于 2024-04-19 22:14:49 发布
本文介绍了一种在Java中精确计算两个长整型数值百分比的方法,通过使用BigDecimal类来避免除法运算中的精度损失,确保了计算结果的准确性。
1848

被折叠的 条评论
为什么被折叠?



