Getting rid of negative null value for float
With SQL Server 2008R2, I get a sign difference when rounding "the same" number as decimal or float.
Sample code showing the difference:
DECLARE @f float = -0.00001;
DECLARE @d decimal = -0.00001;
PRINT CONVERT(varchar,ROUND(@f, 4)) --- outputs -0
PRINT CONVERT(varchar,ROUND(@d, 4)) --- outputs 0
I need to round the float value to 0, not -0.
I think it boils down to the IEEE 754 specification, which defines two zero representations (positive and negative) whereas decimal numbers only have one zero. I think the float equality operator does the job, but I have to compare two AS floating point strings for compatibility reasons.
Is there a / function to get rid of negative zeros (at least when converting to a string)?
+3
source to share