想要防止浮动价值四舍五入─ 如果我的值为Case = 34.9562,我希望看到的数字最多只有1位小数,即34.9,如果为null则显示为空白('')。
我正在尝试不同的方法来防止它通过应用强制转换为十进制(4,1)以及类似的东西进行舍入,但似乎没有任何东西可以阻止它。
使用的数据库是Sql server 2005。
提前致谢
答案 0 :(得分:0)
使用cast
和round
应该有效:
SELECT cast(round(34.9562,1,1) as float)
要将null显示为空白(''),您可以使用case
语句并执行类似的操作
select case when field_name is null then ''
else cast(round(field_name,1,1) as float)
end as my_new_value
from your_table