查询:
declare @a float(10);
declare @b float(10);
declare @c float(10);
set @a = 150.50;
set @b = 19;
set @c = 100;
select @a * @b / @c as result
,ROUND(@a * @b / @c, 2) as rounded
结果:
| result | rounded |
----------------------
| 28.595 | 28.59 |
应四舍五入为28.60吗?我该如何实现?
不使用浮点数,而是一些精确的数据类型,例如decimal():
declare @a decimal(19,5);
declare @b decimal(19,5);
declare @c decimal(19,5);
set @a = 150.50;
set @b = 19;
set @c = 100;
select @a * @b / @c as result
,ROUND(@a * @b / @c, 2) as rounded
结果
result rounded
28.595000 28.600000