Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[token-mod] weird decimal change when substracting 1 from a bar value with preexisting decimals

1744682411
Yui V.
Pro
Sheet Author
I don't know if this is a known occurence, but somehow, when a bar value has decimals, substracting 1 from it with tokenmod tends to substract 0.9000000000000008 (or even 1.11111) or something of that order. Case in point, this example in my image below( on the image,  I copy-pasted bar1's value into the name field, cause it doesn't fit entirely into the bar1 field ): From 2.2, when substracting 1 via the macro, the bar becomes 1.2000000000000002.  The macro I use is simply: !token-mod --set bar1_value|-1 (although the name of the macro is '⛉--1', beginning with a miscelaneaous unicode character, I don't know if that might cause issues, and the phenomenon happens regardless of wich bar is targetted) So that's odd. I'm running Cyberpunk Red, for those who are curious. And I use the decimals to indicate spare ammo and # of dmg dice, I also use the green and blue bar max values as macro storage for attack and initiative (i then just call for bax_max in chat with a macro button) , in order to keep all info on the token itself, thus not needing a linked charsheet.
1744683594

Edited 1744683840
Gauss
Forum Champion
Hi Yui V., You can solve the extreme decimal places using rounding.  If you want it rounded to two decimal places you can do the following:  [[round(X*100)/100]] Where X is the value you want to round off.  Here is how you'd apply it to your situation:  !token-mod --set bar1_value|[[round((@{selected|bar1}-1)*100)/100]] If you want more decimal places, increase the number of zeros. If you want fewer decimal places, decrease the number of zeros. 
1744897268
Yui V.
Pro
Sheet Author
Thanks ! That gets around the problem. I've check and Token-mod is actually not the only API that does this. Chatsetattr seemes to have the same problem, must be a thing about how bars are interacted with by the API?
1744898851
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It likely has to do more with how the attributes are defined, and how computers handle floating point math. Typically a programmer can account for this by rounding results (as Gauss has done above), but you have multiple systems interacting here (Character sheet and mod script.)