坑爹啊
BigDecimal 类型 如果传入是String 产生BigDecimal类型的话 精度是按照字符串里面的精度来的 一位小数和两位小数的坑啊 找了一上午。
package com.ccbtrust.tm.ac.familytrust.distribution;
import java.math.BigDecimal;
public class Testjjj {
public static void main(String[] args) {
String allAmount1=\"25378238.40\";
String allAmount2=\"25378238.4\";
BigDecimal bigDecimal = new BigDecimal(allAmount1);
BigDecimal bigDecimal2 = new BigDecimal(allAmount2);
System.out.println(bigDecimal);
System.out.println(bigDecimal2);
BigDecimal allShare1 = new BigDecimal(839800000);
BigDecimal currentShare1 = new BigDecimal(89800000 );
BigDecimal c1 = calBenefitAmtByAct(allAmount1, allShare1, currentShare1);
System.out.println(c1.toString());
BigDecimal c2 = calBenefitAmtByAct(allAmount2, allShare1, currentShare1);
System.out.println(c2.toString());
BigDecimal c3 = calBenefitAmtByAct2(allAmount1, allShare1, currentShare1);
System.out.println(c3.toString());
BigDecimal c4 = calBenefitAmtByAct2(allAmount2, allShare1, currentShare1);
System.out.println(c4.toString());
}
public static BigDecimal calBenefitAmtByAct(String allAmount, BigDecimal allShare,BigDecimal currentShare) {//按实际利润计算
// TODO Auto-generated method stub
return new BigDecimal(allAmount).multiply(currentShare).divide(allShare,2,BigDecimal.ROUND_HALF_UP);
}
public static BigDecimal calBenefitAmtByAct2(String allAmount, BigDecimal allShare,BigDecimal currentShare) {//按实际利润计算
// TODO Auto-generated method stub
return new BigDecimal(allAmount).multiply(currentShare).divide(allShare,1);
}
}
继续阅读与本文标签相同的文章
-
为什么微软要把数据中心设在水下?数据中心制冷有多花钱?
2026-05-18栏目: 教程
-
PDF转成TXT文本格式,应该如何转换比较快?
2026-05-18栏目: 教程
-
投资10亿!薛城区将开创全新现代化商贸物流模式
2026-05-18栏目: 教程
-
平板笔记本全网相关搜索量排名 平板笔记本全网相关搜索量排行榜
2026-05-18栏目: 教程
-
拼多多开店的5大盲区!赶紧避开
2026-05-18栏目: 教程
