gpt4 book ai didi

sql-server - SQL简单舍入

转载 作者:行者123 更新时间:2023-12-02 20:22:52 25 4
gpt4 key购买 nike

查询:

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 吗?我如何实现这一目标?

最佳答案

我认为你可以使用以下代码

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
,FORMAT(ROUND(@a * @b / @c, 1),'N') as rounded

结果集将是;

+--------+---------+
| result | rounded |
+--------+---------+
| 28.595 | 28.60 |
+--------+---------+

关于sql-server - SQL简单舍入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60333753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com