This code:
SetRoundMode(rmUp); Memo1.Lines.Add(CurrToStr(SimpleRoundTo(10)));
Results in 10,0001.
I simply don’t get it.
I thought that rmUp would do something like, round 10,0001 to 11, but never 10 to 10,0001.
Can anyone explain why this happens?
Thanks.
SimpleRoundToworks like this:The result is a floating-point value. As with most floating-point values, the result will not be exact, even though in your case you start with an exact value. The number of decimal places specified for
SimpleRoundTois negative, so the divisor in step 1, for your example input, will ideally be 0.01. But that can’t be represented exactly as a floating-point number, so when 10 / 0.01 is calculated in step 1, the result is not exactly 1000. The result in step 3 will be exactly 1000, though, so the inexactness of the division isn’t important. The inexactness of the multiplication in step 4 is, though. That product won’t be exact. It will be slightly higher than 10.So
SimpleRoundToreturns a slightly higher value, and since you’ve specified that rounding should go up, the conversion of theExtendedresult ofSimpleRoundToto theCurrencyinput ofCurrToStrresults in exactly 10.0001.Currencyvalues are exact; they represent a fixed-point value, an integer scaled by four decimal places.