kakaroto / Beyond20

D&D Beyond Character Sheet Integration in Roll20
GNU General Public License v3.0
489 stars 144 forks source link

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

Open markusdf opened 1 year ago

markusdf commented 1 year ago

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?

Aeristoka commented 1 year ago

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

kakaroto commented 1 year ago

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.

markusdf commented 1 year ago

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 commented 1 year ago

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.