On  Wed, 20 Jun 2001 at 03:44:44, you wrote:
(ref: <[EMAIL PROTECTED]>)

>At 09:39 18/06/2001 +0200, you wrote:
>>As I see a question about FOR/NEXT loops, I have mine:
>>the subsequent peice of code gives me an unexpected result
>>FOR n = 2.95 to 3.05 STEP 0.01 : print n, INT(n)
>>Why ?
>
>Cumulative roundoff; .01 is not representable exactly in binary, so
>that after 5
>steps you have n = 2.999999..., which PRINT rounds correctly to 3 but
>INT truncates to 2.
>
>I try to avoid fractional STEPs, unless they are inverse powers of 2
>or sums thereof, i.e., exact _binary_ steps.
>
>The following avoids the _cumulative_ roundoff entirely:
>  FOR m = 295 TO 305: n = m/100: PRINT n, INT(n)
That sort of approach is used by accountants isn't it?
>From what I remember they always work in the lowest unit - ie cents or
pence, and then format the output for reports.

I wish I had adopted that approach too in my Archive business progs. -
it is particularly difficult calculating VAT and making sure that totals
are consistent.
-- 
           QBBS (QL fido BBS 2:257/67) +44(0)1442-828255
mailto:[EMAIL PROTECTED]     http://www.firshman.demon.co.uk
        Voice: +44(0)1442-828254      Fax: +44(0)1442-828255
      TF Services, 29 Longfield Road, TRING, Herts, HP23 4DG

Reply via email to