Reading Float data with float variable in stored procedure rounds numbers

Copper Contributor

Hi,

In managemnet studio

 

Declare @@Amount FLOAT
SELECT Sum(Amount) From Docs WHERE DocID IN (104482,104483,104484,104486,104489,104491,104493)
displays in results window 178457,05
 
SELECT @Amount=Sum(Amount) From Docs WHERE DocID IN (104482,104483,104484,104486,104489,104491,104493)
PRINT @Amount

Displays in messages window an actually assings to variable  178457

 

Why is rounding values to 7 length numeric data?

 

Thanks,

Manolis Perrakis

 

 

SQL Server Management Studio 19.3.4.0
SQL Server Management Objects (SMO) 16.200.48053.0+08fe64c9e8eb5ff3c7ea5787f145e9ecb3d57df8
Microsoft T-SQL Parser 17.0.27.0+b6df00d03710e3fafcbe827aad08bdbe9d45d1ab
Microsoft Analysis Services Client Tools 16.0.20054.0
Microsoft Data Access Components (MDAC) 10.0.22621.3958
Microsoft MSXML 3.0 6.0
Microsoft .NET Framework 4.0.30319.42000
Operating System 10.0.22631

1 Reply

@manolis_thess 

When you use PRINT to diplay a float expressions, it will use Implicit conversions rules to convert a float expressions to varchar, just like the result that use CAST like this sample.

DECLARE @a float
SET @a = 178457.05
SELECT CAST(@a AS varchar(20))

 SSMS query result window use other rules to format output, so it looks different.