简体   繁体   中英

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. 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? I always use convert to numeric and round. So: CONVERT(NUMERIC(16,desired_nr_of_decimals), ROUND(decimal_value, desired_nr_of_decimals))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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