Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BUG in round() function?!?
Message
De
29/01/2004 08:55:11
 
 
À
29/01/2004 07:47:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00871732
Message ID:
00871755
Vues:
16
After some more testing i found out that for every decimal between .005 and .995 with a step .01 (=.005, .015, .025,. .035, etc....) you get a different result in the basic numbers that a rounded wrong.
FOR lnDecimal = 0.005 TO 0.115 STEP 0.01
  lnExpected = ROUND(lnDecimal,2)
  FOR lnValueBasic = 1 TO 200
    lnValue = lnValueBasic + lnDecimal
    lnValueLong = ROUND(lnValue,11)
    lnValueRound = ROUND(lnValueLong,2)
    lnDifferenceBasic_Round=lnValueRound-lnValueBasic && has to be lnExpected
    IF lnDifferenceBasic_Round <> lnExpected
      MESSAGEBOX('lnDecimal='+ALLTRIM(STR(lnDecimal,10,3))+', lnBasicValue='+ALLTRIM(STR(lnValueBasic,10,0)))
    ENDIF
  ENDFOR
ENDFOR
Also the number of decimals can make a difference in the result:
FOR lnDecimalRound = 11 TO 12
  FOR lnValueBasic = 1 TO 128
    lnValue = lnValueBasic + 0.325
    lnValueLong = ROUND(lnValue,lnDecimalRound)
    lnValueRound = ROUND(lnValueLong,2)
    lnDifferenceBasic_Round=lnValueRound-lnValueBasic && has to be 0.33
    IF lnDifferenceBasic_Round <> 0.33
      MESSAGEBOX('lnDecimalRound='+ALLTRIM(STR(lnDecimalRound,10,0))+', lnBasicValue='+ALLTRIM(STR(lnValueBasic,10,0)))
    ENDIF
  ENDFOR
ENDFOR
Please help! I'm losing it... I use this round() function a lot!!! And i mean thousands of times in my app's...

Willem-Jan van Ede
Vektis BV
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform