Q: PHP_PDO float to string conversion different than SQLSRV itself After googling around I discovered that PDO_SQLSRV returns string values, as per the php spec for PDO
However, why does the PDO return different values than sql when a sql query has cast a value to a varchar?
PHP:
myDbWrapperFunction("SELECT CAST(CAST(0.03 as varchar(250))as FLOAT)"); // 2.9999999999999999E-2
myDbWrapperFunction("SELECT 0.03"); // .03
myDbWrapperFunction("SELECT CAST(0.03 as varchar(250))"); // 0.03

in SQL itself however:
select cast(cast(0.03 as varchar(250))as float) //0.03
select cast(0.03 as varchar(250)) //0.03
select 0.03 //0.03

I would expect 
myDbWrapperFunction("SELECT CAST(CAST(0.03 as varchar(250))as FLOAT)"); // 2.9999999999999999E-2

to return the same value as 
select cast(0.03 as varchar(250)) //0.03

Is sql cheating with float values?

A: For SQL Server, you need to cast using STR instead of CASTing to VARCHAR:
SELECT STR(MyField,10,2)
Source: http://jwcooney.com/2013/09/25/sql-server-rounds-floats-when-casting-to-varchar/
