CAST money AS FLOAT then INT returns unexpected result for 0.57 when FLOAT is multiplied by 100 - by Puzzled Robin

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 777875 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 1/30/2013 4:48:54 AM
Access Restriction Public

Description

PRINT CAST(CAST(CAST(0.57 as money) AS FLOAT)*100 AS INT)

I would expect the result to be 0.57 but the result returned is 56. Also returns unexpected values for 0.29 and 0.58.
Sign in to post a comment.
Posted by Microsoft on 2/5/2013 at 12:26 PM
Hello,
The behavior you are seeing is by design. Float datatype uses approximate representation and in addition to that we truncate float values when converting to integer data types. See the link below:

http://msdn.microsoft.com/en-us/library/ms173773.aspx

Use decimal data type if you want precision & even with those types you need to be aware of the precision/scale changes based on the arithmetic operation.

--
Umachandar, SQL Programmability Team