• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Help! Coding for calculator


Hutch

Junior Member
#1
I need to put together a correctly functioning calculator swf for an educational site. I have used code from another calculator which works fine apart from the % button. Does anyone know the code which will allow the % button to work correctly?

Thanks in anticipation
 

Hutch

Junior Member
#4
I don't think I explained myself very well. The calculator has to have a correctly functioning % button. The current code for the % button I have is as follows:

on (release, keyPress "%") {
dooperation();
display = Number(display)*100;
operation_s = "%";
}

but I am told by my educational colleagues that does not work correctly and needs to work as the % button shown on this link:
Calculator - Metacalc

Can anybody help?
 

Renniks

Senior Member
#5
Yes and I explained I would do it using multiplication.

% buttons are used to divide or multiply by a given percentage.

To do that I would manually multiply or divide by the [given percentage / 100 ]

problem solved

if they want to do 100 * 50% its equivalent to 100 * 50/100 which is 50....

or 100 / 50% is equivalent to 100 / 50/100 which is 200
 

Hutch

Junior Member
#6
Thanks Renniks but as I said, I need to have a functioning % button as shown in the example, not an alternative way of working out percentages.

Anyone know the code?
 

br3n

Senior Member
#7
oh my god, even I understand this!

THAT IS THE METHOD - the % sign needs to do the multiplication for you!!!!
 

Hutch

Junior Member
#8
Apologies if I'm slow here but code is hardly my forte. If you are referring to a method of code can someone interperate and tell me exactly what code to put in that is likely to make the % button work as it needs to. I have 8 different souce examples and am told that none of them work correctly. Thanks.
 

br3n

Senior Member
#9
My understanding of it is that the % sign completes a mathematical equasion

example you have 20 on the screen and want to multiply by 10%

Action:
20 dividied by 100 (that makes 1%) = 0.2
0.2 then multiplied by 10 (because thats how many percents you want) = 2
Original number (20) multiplied (or added, or subtracted, or divided) by whatever the percentage was (2)
20 * 2 = Final number 40