Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL 'float' data type, when output as XML, causes undesired float result

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

SELECT column1 from Table1; gives values as seen in table.

Say this 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 this fixed? thanks in advance :)

like image 203
Loser Coder Avatar asked Nov 16 '10 00:11

Loser Coder


1 Answers

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

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

you will just need to adjust the precision on the decimal to fit your needs.

like image 164
Ryan Guill Avatar answered Sep 24 '22 10:09

Ryan Guill