使用 sql 删除尾随零 [英] Remove trailing zeroes using sql

查看:39
本文介绍了使用 sql 删除尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
从 SQL Server 中的十进制中删除尾随零

我正在尝试使用 round 函数并且不显示任何尾随零,但最后仍然得到一些零.我想得到 10.4 但得到这样的东西:

I am trying to use the round function and not show any of the trailing zeroes but still getting some zeroes at the end. I am suppose to get 10.4 but getting something like this:

10.400000

这是我的sql:

select round(AVG(CAST(k.TotalNumberDays AS numeric(12,2))),2) TotalNumber

如何删除此处的尾随零?我只需要显示 10.4.

How can i remove the trailing zeros here? I need to show only 10.4.

推荐答案

您只需将其转换为小数 (12,2).

You just have to cast it as a decimal(12,2).

select cast(round(AVG(CAST(k.TotalNumberDays AS numeric(12,2))),2) as decimal(12,2)) TotalNumber

这篇关于使用 sql 删除尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆