Trouble adding...

0 favourites
  • 3 posts
From the Asset Store
Customize the animation of character when item changed
  • Problem Description

    Adding 0.1 to Zero every X Seconds should hit 1, but hits 0.99999

    Attach a Capx

    https://www.dropbox.com/s/i9n5l1ym15b0a ... .capx?dl=0

    Description of Capx

    Every 1 Second add 0.1 to Variable 'Number'

    Steps to Reproduce Bug

    • Run in Debug
    • Look for Variable 'Number'
    • 'Number should hit 1.0

    Observed Result

    Variable 'Number' misses value of 1

    Expected Result

    Variable 'Number' hits value of 1

    Affected Browsers

    • Chrome: (YES)
    • FireFox: (YES)
    • Edge: (YES)

    Operating System and Service Pack

    OS: Windows 10 Pro 64 bit

    Version: 1709

    Build: 16299.334

    Construct 2 Version ID

    Beta release r256

    I feel this must have been discovered already.

    I didn't know how to look it up, I kept getting results not related to this.

    I ended up using

    round((Number + 0.1)*10)/10

    to get the results I wanted.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It’s a computer thing. In base 10 numbers it adds up to 1, but in base 2 the number 0.1 can’t be perfectly represented. It’s actually a tiny bit smaller and after adding it 10 times The error is a bit bigger.

    Anyways you can read more about it by looking up floating point numbers on Wikipedia. You don’t see it in some software because when they display numbers they use less decimal digits so it rounds to 1, at least when it’s displayed. When dealing with decimals in general there is a small amount of approximation so you can’t expect numbers to be exact values.

    Anyways, rounding the number is one solution, as you have done. Another is to just add 1 every time and divide by 10 when you want to use the value.

    A third, albeit needlessly elaborate solution would be to do all the math in a base 10 way and store a decimal as two integers.

  • I had a strong feeling I should of just left this in general. I did move it to Bug, I never heard of this.

    Thanks.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)