我一直在使用BigNumber.js库进行高精度算术计算。为了保持更高的精度,我使用toFixedBignumber 对象的方法,如下所示:
(new BigNumber(6000 )).minus(9006000).div(9006000).times(4503000 ).plus(4503000 ).toFixed()
上面的代码给出的结果为2999.99999999999998275。我尝试使用数据类型在 C# 中验证此计算结果decimal,因为十进制的精度比双精度高,但结果在粒度级别上有所不同。
decimal rg1 = 6000m;
decimal lastSavedRG1 = 9006000m;
decimal lastsavedrefinedgoalMonthly1 = 4503000m;
decimal cal1 = (lastsavedrefinedgoalMonthly1 + (lastsavedrefinedgoalMonthly1 * ((rg1 - lastSavedRG1) / lastSavedRG1)));
该计算给出的值为3000.0000000000000000000001。知道为什么会有这样的差异吗?
有只小跳蛙
狐的传说
随时随地看视频慕课网APP
相关分类