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

Fractional Numbers

Greetings. I am tracking equipment weights on my custom character sheet. How do I use fractional numbers, e.g 1.3    2.6    4.7  etc? I keep getting an annoying error message popping up on the character sheet all the time...see below... Thanks in advance  :)
1562583321
Finderski
Pro
Sheet Author
Compendium Curator
Try adding "step=0.1" or "step=0.01" (depending on how fractional you want to go) to your input syntax. <input type="number" name="attr_whatever" step="0.1">
Finderski said: Try adding "step=0.1" or "step=0.01" (depending on how fractional you want to go) to your input syntax. <input type="number" name="attr_whatever" step="0.1"> Thanks Finderski....I will try that  :D
1562667306

Edited 1562667330
Ray
Pro
That worked perfectly  :D Finderski said: Try adding "step=0.1" or "step=0.01" (depending on how fractional you want to go) to your input syntax. <input type="number" name="attr_whatever" step="0.1"> Do you know a way to prevent a player from entering fractional numbers as inputs?
1562674378
Finderski
Pro
Sheet Author
Compendium Curator
You could use a sheet worker. For the field in question, on change evaluate the number and either round it to the nearest whole number (something like Math.round(), I think?) or just parse it to an int (parseInt()) and then write it back to the field.  That’s the only way I know of for certain, though there are cleverer people who prowl these forums who might have a better/easier solution...
1562674403
Finderski
Pro
Sheet Author
Compendium Curator
Or maybe try step=1
1562842362

Edited 1562842403
Ray
Pro
Finderski said: Or maybe try step=1 Tried the "step=1"....didn't do anything....hmmmm *thinking* Also tried "step=1.0"....same result....
1562857169
GiGs
Pro
Sheet Author
API Scripter
If step=1 doesnt work, you'll need to use a sheet worker. Finderski  said: You could use a sheet worker. For the field in question, on change evaluate the number and either round it to the nearest whole number (something like Math.round(), I think?) or just parse it to an int (parseInt()) and then write it back to the field.  That’s the only way I know of for certain, though there are cleverer people who prowl these forums who might have a better/easier solution... It looks like Ray just wants to make sure player-entered numbers are integers, so no need for rounding, just use parseInt. This can make the sheetworker pretty short. For an attribute named 'whatever' on("change:whatever", function() { getAttrs(["whatever"], function(values) { setAttrs({ whatever: parseInt(values.whatever, 10)||0 }); }); }); If the player enters a non-integer number, when they leave the input (by tabbing out or clicking anywhere else), the number will change to an integer. If you want to do it for a group of attributes, here's a simple way to do it: ['whatever', 'another', 'attribute'].forEach(att => { on(`change:${att}`, function () { getAttrs([att], function (values) { setAttrs({ [att]: parseInt(values[att], 10) || 0 }); }); }); }); Only the first line needs changing. Just change the array [ 'whatever', 'another', 'attribute']  to match whatever attribute names you want processed. This is the simplest example of a  Universal Sheet Worker  I've made yet, so could be informative on how to make them. Compare the two sheet workers and see what needed to be changed.
GiGs said: If step=1 doesnt work, you'll need to use a sheet worker. It looks like Ray just wants to make sure player-entered numbers are integers , so no need for rounding, just use parseInt. This can make the sheetworker pretty short. For an attribute named 'whatever' on("change:whatever", function() { getAttrs(["whatever"], function(values) { setAttrs({ whatever: parseInt(values.whatever, 10)||0 }); }); }); If the player enters a non-integer number, when they leave the input (by tabbing out or clicking anywhere else), the number will change to an integer. If you want to do it for a group of attributes, here's a simple way to do it: ['whatever', 'another', 'attribute'].forEach(att => { on(`change:${att}`, function () { getAttrs([att], function (values) { setAttrs({ [att]: parseInt(values[att], 10) || 0 }); }); }); }); Only the first line needs changing. Just change the array [ 'whatever', 'another', 'attribute']  to match whatever attribute names you want processed. This is the simplest example of a  Universal Sheet Worker  I've made yet, so could be informative on how to make them. Compare the two sheet workers and see what needed to be changed. Spot on with the interpretation GiGs...I want to prevent players assigning fractions of experience points in improving characteristics. The exception being COM and END which cost 0.5xp's per characteristic point, but I deal with those by rounding. Thanks for the sheetworkeer solutions..I will play with them and see which works best. Many Thanks  :D