STR function in SQL

SELECT ltrim (STR (1234.34968311,44,16));

      

Result: 1234.3496831099999000

SELECT ltrim (STR (123.34968311,44,16));

      

Result: 123.3496831100000000

Can someone please help me understand why the first query is returning a varchar value that is not exactly the same as the input.

+3


source to share


1 answer


Because STR operates on the FLOAT datatype, the decimal constant is converted to FLOAT before converting to VARCHAR of the requested size. And as we all know, FLOAT values ​​are the approximate number you thought you would get :-), so you'll get great values ​​after the decimal point.

For example, try STR (1234.1,44,16) and you get 1234.0999999999999000.



If you read the manual at http://msdn.microsoft.com/en-us/library/ms189527.aspx it says float_expression - Is an expression of approximate numeric (float) data type with a decimal point

. Yes, IT'S COMING.

0


source







All Articles