# question

## Unable to get decimals and percentages

Any help is appreciated. I would like the values to show 0.0%. I tried all the following methods but getting error messages: •STR(ROUND(([Future]*100.0/Total), 2) as decimal(5,1)) + '%' as 'Percentage' •Incorrect syntax near the keyword 'AS' •cast(ROUND(([Future]*100.0/Total), 2) as decimal(5,1)) + '%' AS 'Percentage' •Error converting data type varchar to numeric. •CAST(ROUND(([Future]*100.0/Total), 2) as decimal(5,1)) AS 'Percentage' •This gives me the desired result (0.0), but without the % symbol. •str(ROUND(([Future]*100.0/Total), 2)) + '%' AS ‘Percentage’ •This works but without the decimals (0%) STR(CAST(ROUND(([Future]*100.0/Total), 2) as decimal(5,2))) + '%' - This works but again without the decimals (0%) Not sure what am I doing wrong.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
Try this please CAST((CAST(ROUND(([Future]*100.0/Total), 2) as decimal(5,1))) AS VARCHAR)+'%' AS [Percentage]

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks Nidheesh! It worked like a charm.
1 Like 1 ·
Glad to know! Happy to help :)
1 Like 1 ·
What version of SQL Server? If you're on 2012 or above, there's the [`FORMAT`] function. SELECT FORMAT(1.0/2.0,'p') result: 50.00 % : https://msdn.microsoft.com/en-GB/library/hh213505.aspx
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks Thomas. It is 2012 but I'm getting the message "'FORMAT' is not a recognized built-in function name."
0 Likes 0 · 