我有一个存储过程,需要进行大量计算,并将结果存储在几个临时表中。最后计算总和并四舍五入到小数点后两位并存储在临时表中并选择该表。
所有中间和最终临时表的关注列的数据类型均为float。
原始方案:
Declare @Intermediate table
{
 --several other columns
Labor float
--several other columns
};
---Lots of calculation ---xx-----
Declare @Final table
{
 --several other columns
LaborTotal float
--several other columns
};
INSERT INTO @Final  SELECT ROUND(ISNULL((SELECT SUM([Labor]) FROM @Intermediate ),0),2)  AS LaborTotal;
SELECT * FROM @Final;
Result: 7585.22  --> when rounded  //Here is the error Expecting 7585.23
        7585.225 --> when not rounded
测试用例 :
   DECLARE @test float = 7585.225;
   SELECT ROUND(@test,2) AS Result; --> results 7585.23
   SELECT ROUND(7585.225,2) …