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

Rounding Fractions to X Digits

1435098101
Axel
Pro
Sheet Author
How can I round fractions to a specific number of digits? I want a calculation on a character sheet that shows the result with 2 digits. So for example, if my calculation gives a result of 12.58946, I would like it to round that to 12.59 in the displayed number. Is there any way to do this?
1435098539
The Aaron
Pro
API Scripter
Its not pretty, but something like this might work: ((( formula )*100)d1/100) but the nature of floating point math is that you might hit a case where it still has more digits. Someone else might have a better idea... (Brian?)
1435099177

Edited 1435103036
Lithl
Pro
Sheet Author
API Scripter
Using floor((formula) * 100) / 100 may produce nicer results than using d1s. ETA: This would produce 12.58 rather than 12.59. You can substitute round for floor to round the last digit(s) if necessary.
1435100143
The Aaron
Pro
API Scripter
Ah, knew I was forgetting something. Thanks Brian!
1435160787
Axel
Pro
Sheet Author
Thank you very much! Worked like a charm! Now I can choose how many digits to display!