SQL data type "float" when output as XML leads to an undesirable float result

You can try simply: table1: has column1 of type 'float' instead

SELECT column1 from Table1; gives values ​​as shown in the table.

Say it returns 15.1

However, if you try

 Select column1 from Table1 FOR XML PATH('Table1'), Root('SomeRoot'), TYPE 

returns: 1.510000000000000e + 001

Has anyone seen this, and how was it fixed? thanks in advance:)

+6
floating-point xml sql-server
source share
2 answers

This is what you get when working with floating point numbers. You can try this though:

 SELECT CONVERT(varchar(100), CAST(column1 AS decimal(38,2))) 

you just need to adjust the precision of the decimal point according to your needs.

+8
source share

Also, assuming MSSQL, the str function can meet your needs ( MSDN ):

 select str(column1, 3,1) 
+2
source share

All Articles