php - how pdo_sqlsrv driver convert float type to string? -


I set the column type to float some table and set the length to 53, its value is 38.8 I use the sqlsrv driver query, it's okay, the value to show is 38.8. But, when I use the pdo_sqlsrv driver for a query, its show value is 38.799999999999997, why is this?

The decimal number is 38.8 when converted to binary:

  100110.1100110011001100110011001100110011001100110011001100110011001100110 ^^^^ is repeated for ever   

Thus it can not be properly stored in the computer if you have regular numerical format (which has always set the storage size ).

It really does not make any difference: because you have only established for 8 decimal, you should get the right value when you leave the rest:

  ini_set ('Exact', 30); Var_dump (38.8, number-format (38.8, 8)); However, if the strings (11) "38.80000000"   
  float (38.7999999999999 971578290569596) 8  th  Decimal is really important to you, you should switch the column type to  DECIMAL , which stores internally as a string, in this case the exact decimal Contains representation.   

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -