Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full precision output of floating point types in SQL Server Management Studio

I have the value 1555.4899999999998 stored in a float column with default precision (53). When I do a simple select, SSMS rounds the output instead of printing it with all available precision. It's caused some gotchas for me recently since the value printed doesn't work as a float literal to match the actual stored value.

For example (note that both of these numbers have an exact representation in the default float),

declare @f1 float;
declare @f2 float;
set @f1 = 1555.49;
set @f2 = 1555.4899999999998;
select @f1, @f2;
select STR(@f1,30,15), STR(@f2,30,15);

Outputs:

1555.49 1555.49
1555.490000000000000    1555.489999999999800

In Query Analyzer, that first select outputs:

1555.49 1555.4899999999998

That's the behavior I want to get from Management Studio. Is there a way to prevent SSMS from rounding in its result display?

like image 395
Simon Avatar asked Nov 11 '11 20:11

Simon


People also ask

What is the precision of float in SQL Server?

float is used to store approximate values, not exact values. It has a precision from 1 to 53 digits.

What is maximum precision value of float data type?

This representation gives a range of approximately 3.4E-38 to 3.4E+38 for type float.


1 Answers

No.

SQL Server Management Studio rounds floating point values for display purposes; there is a Connect suggestion to change this behavior, but it is closed "as By Design". (Microsoft Connect, a public issue tracker for Microsoft software has been retired)

However, SQLCMD, osql and the Query Analyzer do not.

SQLCMD -E -S server -Q"SELECT CONVERT(FLOAT, 1555.4899999999998)"
like image 172
gonsalu Avatar answered Oct 10 '22 19:10

gonsalu