Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] v3.4.1 Stable - Internal Variable Rounding Error #3066

Open
2 tasks done
Poncho42 opened this issue Oct 2, 2024 · 3 comments
Open
2 tasks done

[BUG] v3.4.1 Stable - Internal Variable Rounding Error #3066

Poncho42 opened this issue Oct 2, 2024 · 3 comments
Labels
BUG Something isn't working

Comments

@Poncho42
Copy link

Poncho42 commented Oct 2, 2024

Is this a bug in companion itself or a module?

  • I believe this to be a bug in companion

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Incrementing a custom internal variable by 0.1 has rounding errors making numbers 18 significant digits long

Steps To Reproduce

  1. Create internal Variable $(internal:custon_round)
  2. Set Start value to 0.5
  3. Make a Button
  4. Add Action "internal: Custom Variable: Set with expression"
  5. Change Custom Variable to "A custom Variable (internal:custon_round)
  6. input "$(internal:custom_round)+0.1
  7. Press Button 2-5 times and see the rounding issue

Expected Behavior

After 3 presses expected output is 0.8, actual output is 0.7999999999999999

Environment (please complete the following information)

- OS: Windows 11 Pro
- Browser: Chrome
- Companion Version: v3.4.1

Additional context

First couple of button presses add properly, but the farther you get from the starting value the more off it gets.

@Poncho42 Poncho42 added the BUG Something isn't working label Oct 2, 2024
@thedist
Copy link
Member

thedist commented Oct 2, 2024

Javascript is notoriously bad for floating point math. I'm not sure if this is something that can easily be fixed on Companion's side, or more so raise awareness on the users side so that appropriate steps can be taken to handle the math inaccuracies of JS as different users may accept different ways to handle it (including not handling it at all if the issue is insignificant for their use case).

@Poncho42
Copy link
Author

Poncho42 commented Oct 2, 2024

interesting. is there something similar i can put into the formula bar similar to excel's "round(variable, 0)"?

@thedist
Copy link
Member

thedist commented Oct 2, 2024

If you press the Getting Started button in the Companion web ui, and then go to Secondary admin controls > Expressions > Functions, it'll show how to do rounding, ceiling, floor, things like that within Expressions.

Another way to handle JS's math issues is to deal with whole numbers when manipulating them, then dividing them when you want to use/display them. For example rather than using 0.5, and then adding/subtracting 0.1, instead start with 5 and add/subtract 1, and if you want to display that value on a button you could do the Expression $(internal:custom_round) / 10, which should be accurate. If you wanted to use it as an option in an action or feedback you could use a trigger so that when $(internal:custom_round) changes, $(internal:custom_round_floating_point) or something changes which would be $(internal:custom_round) / 10. None of these are particularly ideal, and it all adds extra steps in, but it's one of the quirks of JS unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants