简体   繁体   English

使用Cast as Decimal时如何删除不需要的尾随零?

[英]how to remove undesirable trailing zeros when using Cast as Decimal?

I am using below statement in Microsoft SQL Select statement and the result i am getting is like "100.00000000000" however i would like it to be as "100.00".. ie Only two trailing zeros after period. 我在Microsoft SQL Select语句中使用下面的语句,我得到的结果是“ 100.00000000000”,但是我希望它是“ 100.00”。即,句点后只有两个尾随零。 Can some one tell what i am missing here and how to fix it 有人可以告诉我我在这里缺少什么以及如何解决它

round(Cast(count(Case when Newuser = 1 then 'Yes' end)as decimal) / count(Totalusers),4)*100 as '% New Users''

This is a matter of representation as a string / varchar, right? 这是表示为字符串/ varchar的问题,对吗? I always use convert to numeric and round. 我总是使用转换为数字和舍入。 So: CONVERT(NUMERIC(16,desired_nr_of_decimals), ROUND(decimal_value, desired_nr_of_decimals)) 因此:CONVERT(NUMERIC(16,desired_nr_of_decimals),ROUND(decimal_value,wanted_nr_of_decimals))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM