The issue that might rise is rounding issue.
.973684210526315789*100 -> 97.37 False
.973684210526315789*100 -> 97.36 True
there exist two approaches: String Functions
and Numerical Functions
String Functions
can avoid rounding issue, use functions such as CAST
( equivalent CONVERT
) and LEFT
SELECT LEFT(Cast(.973684210526315789*100 AS VARCHAR(100)), 5) + ' %'
SELECT LEFT(CONVERT(VARCHAR(100), .973684210526315789*100), 5) + ' %'
Numerical Functions
might bring rounding issue, to avoid it use ROUND
function
SELECT LEFT(Round(.973684210526315789*100, 2, 1), 5) + ' %'
to avoide using LEFT
function(String Functions) use DECIMAL(18,2)
and NUMERIC(18, 2)
in cast and convert.
SELECT Concat(Cast(Round(.973684210526315789 * 100, 2, 1) AS DECIMAL(18, 2)),' %')
SELECT Concat(CONVERT(NUMERIC(10, 2), Round(.973684210526315789 * 100, 2, 1)),' %')
in addition you can use FORMAT
, ###.##
and 00.00
resemble integer part and fractional part and ###.##
should be preferred to 00.00
since it can avoid zero values
SELECT FORMAT(Round(.973684210526315789*100, 2, 1), '######.#####')+ ' %' ---> 97.36%
SELECT FORMAT(Round(.973684210526315789*100, 2, 1), '00000.0000')+ ' %' ---> 00097.3600%
SELECT FORMAT(Round(.973684210526315789*100, 2, 1), '00.00')+ ' %' ---> 97.36%
sqlfiddle