Sql-server – Why is the output of this query being returned like this

sql serversql-server-2008t-sql

I have a T-SQL query :

select 
    CAST(0 as float(53)),
    CONVERT(nvarchar(max),CAST(0 as float(53)),128)

the output of which is

0  ,  0.0E0

Can some one explain why it is not 0 , 0? The database is SQL Server 2008.

Best Answer

Syntax for CONVERT:

 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

[style] for float data type :

0 (default)   A maximum of 6 digits. Use in scientific notation, when appropriate.
1 Always 8 digits. Always use in scientific notation.
2 Always 16 digits. Always use in scientific notation.
126, 128, 129 Included for legacy reasons and might be deprecated in a future release.

You can use below command to get expected result :

CONVERT(nvarchar(max),CAST(0 as float(53)),0)