More maths stuff.
Posted: Thu Jun 12, 2014 1:28 am
Another quick example:
Filling the array may take a little while, and using this method to work out percentages at least gets rid of the potential for a division by zero error (ie, human input error usually), as 0% of single number will be 0. The array is essentially being used like a look-up table. Also, it doesn't calculate above 99%, nor will it do 22.25% for instance.
True story: The dev next to me was using division to work out percentages on a recent project. Apart from the rounding difference across PHP and Javascript that we were using, division wasn't always going to work. For instance, 99 / 33 is 3, and yet 33% of 99 is 32.67. You probably all know this, but percentages have a certain symmetry to them in that 33% of 99 is the same as 99% of 33 Mathematics is the reason that I want to improve my mathematics.
Regards,
Shaun.
Code: Select all
10 dim pc(99): rem will be used to calculate percentages later
20 let pc = 100: rem used to fill array
30 for i = 0 to 99: rem fill array loop
40 let pc(i) = i/pc: rem enter multiplier for each array position
50 next i: rem end loop
60 input "enter the number"; a: rem a is for the number and b for the percentage
70 input "now enter the percentage of that number you want to work out";b
80 print
90 print "{left}"; b ;"{left}% of"; a ;"is"; a*pc(b)
True story: The dev next to me was using division to work out percentages on a recent project. Apart from the rounding difference across PHP and Javascript that we were using, division wasn't always going to work. For instance, 99 / 33 is 3, and yet 33% of 99 is 32.67. You probably all know this, but percentages have a certain symmetry to them in that 33% of 99 is the same as 99% of 33 Mathematics is the reason that I want to improve my mathematics.
Regards,
Shaun.