User Tag List

Results 1 to 10 of 10

Thread: percent calculation with counter

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module

    Join Date
    Jan 2010
    Posts
    545
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    percent calculation with counter

    Hi,
    I am trying to do something that seems extremely straightforward but for some reason is not working. I am trying to calculate a percentage and have a counter always display the percentage. It is for an educational game and I have set up global values for number correct and number incorrect. I create the following event:
    Always Set Counter to... global value for number correct/(global value for number correct+global value for number wrong)x 100. This should work but it keeps returning a zero whenever there is a wrong answer. Why? The calculation seems very straightforward. It's just a percentage. Any ideas? Thanks,
    Brett

  2. #2
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    This is quite a common issue - the short answer is that MMF, like many coding languages, only works in non-whole numbers if you tell it to. What's happening with that expression is that the division is done first, and rounded to 0 - then the multiplication has no effect. This will work:

    (Correct * 100) / (Correct + Wrong)

    As the multiplication is done first, you don't get the rounding error during the division.

    Alternatively, if you multiply the value by 1.0 before doing anything to it, then the answer will come out as a decimal (floating-point) value:

    (Correct * 1.0) / (Correct + Wrong) * 100

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module

    Join Date
    Jan 2010
    Posts
    545
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    Thanks David,
    Your suggestion worked perfectly. Have a great day.
    Brett

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module

    Join Date
    Jan 2010
    Posts
    545
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    Hi,
    I've noticed another strange thing. Upon initial testing everything was working well but I noticed that after answering several questions correctly the percentage would randomly drop to 99%, 96% or some other high percentage. No questions had been answered incorrectly so I cannot figure out why there would be a small random calculation error. Any ideas? Thanks,
    Brett

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Eliyahu's Avatar
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    Check the correct and wrong values in the debugger to see what they are. Maybe correct and wrong are not what you expect them to be. DavidN's equations should both work.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module

    Join Date
    Jan 2010
    Posts
    545
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    Hi Eliyahu,
    I tried them in the debugger and using counters. The values displayed are correct. I agree that the equation should work, but it seems to randomly not work. I'm not sure why. Please let me know if you have any other ideas. Thanks,
    Brett

  7. #7
    No Products Registered

    Join Date
    Jan 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    Try to always include .0 in all numbers. For example if you multiply by 100 make it 100.0 and so on. If you have any fixed whole number that will not change but has the possibility of becoming a decimal or returning a decimal, do it always with .0 at the end. It's something weird I found out about MMF...

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module

    Join Date
    Jan 2010
    Posts
    545
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    Hi Geohound,
    Thanks. Adding the .0 at the end and limiting the number of significant digits fixed the problem. Thanks,
    Brett

  9. #9
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    I saw your message this morning - it's good to know you got help I imagine that in some cases you were ending up with a 33.3% that was being multiplied up to 99.9% and then rounded down, or something like that.

  10. #10
    No Products Registered

    Join Date
    Jan 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: percent calculation with counter

    Glad to hear.

Similar Threads

  1. calculation help
    By aylictal in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 21st May 2013, 02:45 PM
  2. Max() calculation error
    By DavidN in forum XNA Export Module Version 2.0
    Replies: 7
    Last Post: 11th October 2012, 07:12 AM
  3. Opacity/Transparency percent
    By FlinkGigitty in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 23rd August 2010, 06:01 PM
  4. Converting screen pixels into percent.
    By Nickydude in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 10th November 2009, 06:10 AM
  5. Percent Occurance?
    By KingToast in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 24th July 2007, 07:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •