> From: [EMAIL PROTECTED] (Sadhunathan Nadesan)

> Problem:  after calculating a result like the above, I add it to 3
> different globals -  a column total, a line total, and a cumulative
> total.  If there is only one column, all three numbers should be the
> same but eventually, they start getting out of sync with each other, a
> penny or two off.

The code you supplied and put into EXAMPLE 2 below works OK.  EXAMPLE 1
below shows a similar rounding problem that can occur with the MC format
function.  The format function with a format of %6.2f rounds 1.3350 to 1.33,
whereas round(1.3350, 2) returns 1.34.  My summer students discovered this
last week in homework 1 with similar behavior of MC format function and True
Basic's PRINT USING instruction.  None of this may have solved your problem,
so good luck!

Rich Herz <[EMAIL PROTECTED]>

# EXAMPLE 1: script of button that displays output in fld 3

# DISPLAY IN FLD 3:
price = 133.50
tax =   1.33
total = 134.84
total 2 = 134.83
total 3 = 134.84

on mouseUp
  put 133.50 into price
  put 1.3350 into tax
  put tax + price into total
  put format ("price = %6.2f", price) into line 1 of fld 3
  put format ("tax = %6.2f", tax) into line 2 of fld 3
  put format ("total = %6.2f", total) into line 3 of fld 3
  put format ("%6.2f", tax) into tax2
  put "total 2 = " & tax2 + price into line 4 of fld 3
  put round(tax, 2) into tax2
  put "total 3 = " & tax2 + price into line 5 of fld 3
end mouseUp

# EXAMPLE 2:  script of button that displays output in fld 1

global category_total, cumulative_total, line_total

on mouseUp
  put 0 into category_total
  put 0 into cumulative_total
  put 0 into  line_total
  put empty into fld 1
  repeat 10000 times
    put rounder() into temp
  end repeat
  put category_total into line 1 of fld 1
  put cumulative_total into line 2 of fld 1
  put line_total into line 3 of fld 1
end mouseUp

function rounder
  put random(100)/100 into factor
  put random(1000)/10 into rate
  put random(100) into number_of_performers
  put factor * rate * number_of_performers into temp_category_total
  put (round(100 * temp_category_total) / 100) into category_total
  # alternative:
  # put round(temp_category_total, 2) into category_total
  put cumulative_total + category_total into cumulative_total
  put line_total + category_total into line_total
  return category_total
end rounder


Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to