Try running the following query and you’ll see what we’re talking about:
DECLARE @TestValue float — or real
SET @TestValue = 6.9
SELECT TestValue = @TestValue
And you won’t see the result you might expect (6.9). Rather, you see 6.9000000000000004 for float or 6.9000001 for real. (Remember that real is just a synonym for float(24)).
Why does this occur? According to SQL BOL, floating point data is approximate by design and "not all values in the data type range can be precisely represented." So what do you do when you need precise fractional values? Use decimal instead.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.