Member Offer
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help! Coding for calculator

Discussion in 'Website Design Forum:' started by Hutch, Aug 26, 2009.

  1. Hutch

    Hutch Junior Member

    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
  2. Renniks

    Renniks Senior Member

    use the multiply?
    where 30% of x => x * 0.3 ( which is 30/100 ) ....
  3. Kevin

    Kevin Senior Member

    That makes sense... Did you try that?
  4. Hutch

    Hutch Junior Member

    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 "%") {
    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?
  5. Renniks

    Renniks Senior Member

    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
  6. Hutch

    Hutch Junior Member

    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?
  7. br3n

    br3n Senior Member

    oh my god, even I understand this!

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

    Hutch Junior Member

    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.
  9. br3n

    br3n Senior Member

    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%

    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

Share This Page