I am trying to format a decimal number with +/- sign with one digit after the decimal. I am using below query
select FORMAT(-0.034, '+0.0;-0.0')
And I am getting +0.0 in the output instead of -0.0
In a similar situation, using an expression (variable) as a value of the format
parameter, was an option:
SELECT FORMAT(
[Number],
CONCAT(
'+0.0;-0.0;',
CASE
WHEN [Number] < 0 THEN '-0.0'
WHEN [Number] > 0 THEN '+0.0'
ELSE ' 0.0'
END
)
) AS [Result]
FROM (VALUES
(-0.034),
(0.034),
(0),
(0.153),
(-0.153)
) v ([Number])
Result:
Result
------
-0.0
+0.0
0.0
+0.2
-0.2