User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Decimal hell.

  1. #1
    No Products Registered

    Join Date
    Feb 2009
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Decimal hell.

    I'm very frustrated cos what I thought would a simple task turned out to be hellish.

    I'm trying to make a simple function which finds percentages. I am doing this by having the user input a number on a box and the other number on another box.. EG: What percentage is 50 of 100? The result should be a simple 50, but it returns 0. I already tried changing 100 to 100.0 and it just doesn't work, some numbers just won't come out and others will give erratic results. This is my formula:

    First Box / Second Box * 100.0

    As far as I know I am doing nothing wrong. Thank you for yer help.

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,367
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)

    Re: Decimal hell.

    Try:
    First box / (second Box * 100.0)

    This will make the second number into a float before the calculation.

    Now, it probably does this:

    Integer / Integer = Integer
    Integer * Float = Float

    ...which as you see, converts the result into a float AFTER the first calculation.

  3. #3
    No Products Registered

    Join Date
    Feb 2009
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Decimal hell.

    Quote Originally Posted by Popcorn
    Try:
    First box / (second Box * 100.0)

    This will make the second number into a float before the calculation.

    Now, it probably does this:

    Integer / Integer = Integer
    Integer * Float = Float

    ...which as you see, converts the result into a float AFTER the first calculation.
    Tried and it partially fixes the problem. Now it does show decimals, but let's say we use the easy what % 50 is of 100, it will only show 0.005 as if it was dividing by 100 instead of multiplying.

    :crazy:


    EDIT: Seems after doing that I had to multiply it by 10000 for it to work... I did not know MMF worked like this? Why is that?

    EDIT 2: Darn! Sometimes it gives wrong percentages now... I did randomly try to do what percentage 60 was of 2.99999 and it said 3000 when when I do it on a number of other ways it says 2000.006666688889. I'm kind of really confused about this...

  4. #4
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Decimal hell.

    The correct formula is: (First box * 100.0) / second Box. Always do multiplies first if you can, it's more accurate.

    Also popcorn had the multiply grouped under the divide, so it effectively became a divide by 100...

  5. #5
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    14,022
    Mentioned
    279 Post(s)
    Tagged
    3 Thread(s)

    Re: Decimal hell.

    1. You should do : (First box * 100.0) / second Box

    EDIT: ah, Dynasoft was faster

    2. It's due to the way computers store floating point values. Already discussed here.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,367
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)

    Re: Decimal hell.

    Haha, it was early in the morning
    Sorry for the confusion!

  7. #7
    No Products Registered

    Join Date
    Feb 2009
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Decimal hell.

    Thanks for all the help guys, really. By doing that it works just fine, but still gives some erratic values. Like that 60 of 2.99999
    it returns 3000% which I know is very incorrect given the fact that, any other method returns 2000.006666688889%. Why is this? Any way to correct this?

  8. #8
    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: Decimal hell.

    It definitely sounds like something else is wrong - maths just isn't this... erratic! I would check any other events that could possibly be affecting any of those counters or values...

  9. #9
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Decimal hell.

    You'd get 60 of 2.99999 = 3000% if you were rounding down the 2.99999 to 2. You're not using "value of editbox" are you? Use "Val()" on the "text of editbox" instead.

  10. #10
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Århus
    Posts
    3,456
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    Re: Decimal hell.

    Yes the expression of the edit box to get the nummeric value only returns integers. As Dynasoft sais you have to use Val() on the text of the edit object.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Decimal places?
    By ChrisBurrows in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 23rd October 2011, 08:07 PM
  2. hex to decimal??
    By Gibbon in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 24th June 2009, 03:05 PM
  3. stdrt.exe ? What the hell?
    By GabSt in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 21st September 2008, 05:52 PM
  4. Bad Object deleted my whole game! What the hell?!
    By MechatheSlag in forum Multimedia Fusion 2 - Technical Support
    Replies: 12
    Last Post: 12th June 2008, 07:52 AM

Posting Permissions

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