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

How to remove decimal numbers without rounding?

April 28 (1 year ago)
Mago
Pro
Sheet Author

Hello forum

is there a way to remove decimal numbers from a roll on the chat without rounding?
The floor/ceil/round functions do not apply to my work since i only need the natural number (not rounded) because rounding it would change the value.

if there is a way, does it apply to rolls in the chat? is it usable within a custom rolltemplate?


any help would be appreciated

April 28 (1 year ago)
Andrew R.
Pro
Sheet Author

Perhaps you could explain how you are getting numbers with decimal places?

It would help if you told us what game system and character sheet you are using, as usual.

April 28 (1 year ago)
Mago
Pro
Sheet Author

sure the system is WH40k Rogue trader by FFG

im using Rogue Trader Improved sheet (im the author)


in the game, players roll a 1d100 and compare it to their target number (attributes + bonus)
rolling less than or equal to the target number is a success, rolling over is failure

however there is an additional mechanic that for every 10 "points" difference roll vs target the player gets 1 "Degrees of success or failure"

e.g. Weapon skill test:

Attribute + bonus = 50

1d100 roll = 30 <--- this roll is success

50-30= 20/10 = 2 "Degrees of success"


e.g.2  Weapon skill test:

Attribute + bonus = 50

1d100 roll = 70 <--- this roll is failure

50-70= -20/10 = -2 "Degrees of failure"


here is a macro example:
&{template:custom} {{name=**@{character_name} Test Weapon Skill**}} {{result=[[(@{WeaponSkill}+?{Modifier|0}-1d100cf100cs1)/10]] }}


When having roll values like 17 or 36, dividing by 10 always gives decimal numbers (1.7 or 3.6) for example

rounding up these values would give the player extra degrees of success that should not have

rounding down is the solution for positive numbers, however for negative numbers (in the case of failure), rounding down would give the player extra degrees of failure that should not have

ceil/floor/round math functions in macros cannot be combined as far as im aware, thats why the sheet macros do not have those


what im looking for is a way to remove the decimal numbers from the roll displayed in chat without rounding the result

You could use

[[(@{WeaponSkill}+?{Modifier|0}-1d100cf100cs1) * 100 % 999 % 100]]

It works by rotating the digits of the number (so 017 -> 701, or -023 -> -302) then removes the now largest digit that would have caused any remainder. What's left is already divided by 10, preserves pos/neg sign and doesn't round.

April 28 (1 year ago)

You may want to use rounding in your roll formulas to emulate mechanics such as "half a level, rounded down to the nearest level."


/roll floor(11/2) + 1d6
April 28 (1 year ago)
timmaugh
Forum Champion
API Scripter

First, that's an elegant solution, Rainbow! Stashing that one away in my "RainbowEncoder Examples" bookmark folder. =D

As for the original question, if scripts are available then there are a few ways to do it with the Metascript Toolbox. Here are just 2:

Re-Use the Roll

One limit to doing a modulo operation on the original roll is that you can't use a roll for further inline roll math operations outside of its hierarchy of nesting. That's a mouthful. Let's just say: you can't do math on reused rolls. You can report their value, but you can't use them in another roll.

But metascripts can extract the value and run another round of inline rolls. Here is an example:

!&{template:default}{{name=Proof of Concept}} [\][\] [[[[[[1d100]] - (@{WeaponSkill} + ?{Modifier|0}) ]]/10]] - ($[[2]] % 1) \]\] {{d100=$[[0]]}} {{Target=[\][\]@{WeaponSkill} + ?{Modifier} \]\] }}{{d100-Target=$[[1]]}} {{Div by 10=$[[2]]}} {{Final=$[[3]]}} {&simple}

That's a lot of verbiage just to unpack the various parts for reporting. The key bit is the roll, which is really in two parts. First, the rolls that happen immediately (the original stack of nested inline rolls):

[[[[[[1d100]] - (@{WeaponSkill} + ?{Modifier|0}) ]]/10]]

The levels of nesting are there for later reporting (pulling out the d100 roll by using roll $0, etc.). If you didn't want (or need) to report those individual values, you could collapse all of that to a single roll and just adjust the roll marker index in the modulo operation (the next portion).

The next portion... is... the result of the first set of inline rolls performing a modulo-1 to get just the decimal portion, which we subtract:

[\][\] ...previous stuff... - ($[[2]] % 1) \]\]

Here is an example of this working:

If you go this route, you could further dress things up by using APILogic (part of the Toolbox) to test if the final answer was positive or negative, and labeling it "Degrees of Success" or "Degrees of Failure".

Use MathOps to Truncate the Result

In MathOps (another metascript in the Toolbox) you can perform a truncation operation to remove the decimal portion of a number and just return the integer (in effect, always rounding toward 0). That is even simpler than the above, and would look like this:

!&{template:default}{{name=Proof of Concept}} [[[[[[1d100]]-(@{WeaponSkill} + ?{Modifier|0}) ]]/10]] {{d100=$[[0]]}} {{Target=[\][\]@{WeaponSkill} + ?{Modifier|0} \]\] }}{{d100-Target=$[[1]]}} {{Div by 10=$[[2]]}} {{Final={&math trunc($[[2]])} }} {&simple}

We no longer need the second set of rolls (I left the roll in the "Target" template part just to let you hover over the result to see the math, if you wanted, but in practice you probably wouldn't need this line of reporting). Instead, all of the work is done in the MathOps {&math} tag, found in the "Final" template part.

Here is an example of this working:

Again, you could use APILogic to further dress this up, and/or you could put the MathOps operation in an inline roll, itself, if uniformity of the final presentation of numbers was important.

April 28 (1 year ago)
Mago
Pro
Sheet Author


RainbowEncoder said:

You could use

[[(@{WeaponSkill}+?{Modifier|0}-1d100cf100cs1) * 100 % 999 % 100]]

It works by rotating the digits of the number (so 017 -> 701, or -023 -> -302) then removes the now largest digit that would have caused any remainder. What's left is already divided by 10, preserves pos/neg sign and doesn't round.


This is brilliant and works like a charm!

timmaugh said:

First, that's an elegant solution, Rainbow! Stashing that one away in my "RainbowEncoder Examples" bookmark folder. =D

As for the original question, if scripts are available then there are a few ways to do it with the Metascript Toolbox. Here are just 2:


thank you for your suggestions, im trying to not use any API scrips but i will test this on a custom sheet 


April 28 (1 year ago)
Andrew R.
Pro
Sheet Author

Really impressive roll calculation, RainbowEncoder. Bravo!