That type of formatting should probably be done in your application layer rather than in SQL Server.
You would use the column name discount_perc
instead of 0.4
in the following examples:
You can use cast()
like so:
select cast(cast(0.4*100 as int) as varchar(12))+'%'
returns: 40%
rextester demo: http://rextester.com/PSPVY57957
In SQL Server 2012+ you can use format()
:
select format(0.4,'0%')
returns: 40%
But format()
can be slower, take a look here: format()
is nice and all, but… - Aaron Bertrand
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.