在 MS SQL Server 中将数字格式化为百分比

编程入门 行业动态 更新时间:2024-10-25 20:31:04
本文介绍了在 MS SQL Server 中将数字格式化为百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图简单地将数字格式化为带有两位小数的百分比.如果是 37 除以 38(又名 .973684210526315789),我希望它在 SQL 输出中显示 97.36%.我知道建议在应用程序中进行格式化,但这是为了自动导出.这是使用 SQL Server 2008.

I am trying to simply format a number as a percent with two decimal places. If it is 37 divided by 38 (aka .973684210526315789), I would like it to show 97.36 % in the SQL output. I know it is recommended to do formatting in the Application, however this is for an automated export. This is using SQL Server 2008.

这是我现在所拥有的:

select CONVERT(VARCHAR(50),cast(37 as decimal)/cast(38 as decimal)*100)+' %' AS [%]

如果您能在任何有用的函数中解释各种参数的含义.

If you could explain what the various parameters are as well in any function that would be helpful.

推荐答案

M.Ali的回答可以修改为

M.Ali's answer could be modified as

select Cast(Cast((37.0/38.0)*100 as decimal(18,2)) as varchar(5)) + ' %' as Percentage

更多推荐

在 MS SQL Server 中将数字格式化为百分比

本文发布于:2023-10-30 08:03:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542260.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:百分比   中将   格式   数字   MS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!