I need to convert a decimal to a percent. Here is what I have:
When I make @pValue equal to any of the below I get the correct percent except for .125 where I get 12%. What I want is 12.5%. Can someone please help? I've tried other ways but I'm sure there are easier ways then the ones I found and I want this to be done right.
'1' = 100%
'.25' = 25%
'.125' = 12%
'.05' = 5%
Code:
DECLARE @MonetaryValue NUMERIC(10, 3),
@ReturnValue VARCHAR(5),
@pValue VARCHAR(7)
SET @pValue = '.125'
SET @MonetaryValue = CAST(@pValue AS NUMERIC(10, 3))
SET @ReturnValue = CAST(CONVERT(INT, 100 * @MonetaryValue) AS VARCHAR(5)) + '%'
SELECT @ReturnValue
When I make @pValue equal to any of the below I get the correct percent except for .125 where I get 12%. What I want is 12.5%. Can someone please help? I've tried other ways but I'm sure there are easier ways then the ones I found and I want this to be done right.
'1' = 100%
'.25' = 25%
'.125' = 12%
'.05' = 5%