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

Using "add tiebreaker to initiative roll" should round extra floating point digits #1075

Open
markusdf opened this issue Jul 24, 2023 · 4 comments
Labels
invalid This doesn't seem right

Comments

@markusdf
Copy link

Using "add tiebreaker to initiative roll" with Foundry VTT, on occasion the initiative is displayed in Foundry with extra digits in the decimal (e.g. 7.1400000000001)
image

could this be truncated, or rounded to 2 decimal points?

@markusdf markusdf added the bug Something isn't working label Jul 24, 2023
@Aeristoka
Copy link
Collaborator

That's a purely cosmetic bug that has been around forever. It doesn't hurt anything.

@kakaroto
Copy link
Owner

It already is truncated to 2 decimal points:
image

The issue is javascript having those kinds of issues so that if you do 5 + 2.14 it gives 7.14000000000001 because of floating point precision in the javascript engine, because that's the closest value it can get to 7.14 which is an impossible value to hold in memory in the language.
Yes, it's stupid and infuriating and people keep facepalming about this.

@Aeristoka Aeristoka added invalid This doesn't seem right and removed bug Something isn't working labels Jul 24, 2023
@markusdf
Copy link
Author

markusdf commented Aug 4, 2023

toFixed returns a string, so is initiative being turned back into a float again before being output in the html? Seems like it needs another toFixed(2) when rendering the output.

@kakaroto
Copy link
Owner

kakaroto commented Aug 5, 2023

toFixed returns a string, so is initiative being turned back into a float again before being output in the html? Seems like it needs another toFixed(2) when rendering the output.

yes, we make that into a string, something like 1d20 + 2.14 which is then rolled within Foundry. The roll's total then becomes what you've seen.
We can't toFixed(2) when rendering the output otherwise every other roll would appear with .00 at the end.
There might be something we can do about specifically non-integer roll results, but I don't know if it's within our power at that moment since I believe that roll is generated by Foundry and posted to the chat log directly by Foundry, not by Beyond 20. We just tell it the formula to roll.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants