我有一个销售税值,我需要将其平均分配到 3 个项目中。例如:$153.88/3 = 51.29333333333333
当四舍五入到小数点后 2 位以表示货币时,it = $51.29
. 但是$51.29*3=$153.87
,这比总税额少 1 美分。
是否有解决这些舍入误差的功能,以便各个值始终加起来?那么额外的 1 美分随机分配给 1/3 项?
select '1' as item_number, 153.88 as sales_tax, round(153.88 /3,2) as rounded
union all
select '2' as item_number, 153.88 as sales_tax, round(153.88 /3,2) as rounded
union all
select '3' as item_number, 153.88 as sales_tax, round(153.88 /3,2) as rounded