0

Here is the example :

DECLARE @V1 FLOAT
SET @V1 = 0.05
DECLARE @V2 FLOAT
SET @V2 = 1.00
DECLARE @V3 FLOAT
SET @V3 = 102.90
SELECT @V1*@V2*@V3
SELECT ROUND(@V1*@V2*@V3, 2)

Result 5.145

Result 5.15

DECLARE @V1 FLOAT
SET @V1 = 0.05
DECLARE @V2 FLOAT
SET @V2 = 10.00
DECLARE @V3 FLOAT
SET @V3 = 10.29
SELECT ROUND(@V1*@V2*@V3, 2)

Result 5.145

Result 5.14

James Z
  • 12,209
  • 10
  • 24
  • 44
jeromeb
  • 3
  • 2
  • 4
    Floating point numbers are not exact. You can get variation in the lowest order digits. So, 5.144000000001 rounds one way, 5.143999999997 rounds the other way. – Gordon Linoff May 17 '17 at 16:07
  • The calculation of 0.05 * 1.00 * 102.90 and 0.05 * 10.00 * 10.29 should be the same ? – jeromeb May 17 '17 at 16:15
  • 2
    FLOAT is an approximate value. That is the answer. It's not the same because it's not exact. – Jacob H May 17 '17 at 16:21
  • Stop using FLOAT and ROUND. Use DECIMAL(10,2) and then convert the product to this same definition and the "problem" should go away. – Aaron Bertrand May 17 '17 at 16:49

0 Answers0