Code: Select all
// 33.49 plus VAT would be:
printf("%.2f", 33.49 * 1.2);
Code: Select all
10 def fn u(a) = int(a)+(int(100*(a-int(a)))/100)
20 def fn r(a) = a+2^-24
30 input "please enter a floating point number";a
40 a = fn u( fn r(a) )
50 print "to two decimal places, it's:"a;
60 if a = fn r(int(a)) or a = int(a) then print"{left}.00"
70 for i=10 to 90 step 10
80 if fn u( fn r(a-int(a)) ) = fn u( fn r(i/100) ) then print "{left}0"
90 next i
100 poke 198,0:wait 198,1
The function in line 20 seems to help in eliminating rounding errors.
Obviously I haven't tested all real numbers and it truncates rather than rounds up to the nearest penny (for instance). Does anyone know of a better method?
Edit: typo alert, n * 1.8 would not give you price + VAT as VAT is not 80% - corrected.
Regards,
Shaun.