• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

A question regarding the round() function

TobyFox2002

Well-known member
I have a piece of code I'm trying to understand, its probably very simple but still giving me some big grief. I'm fairly certain I've seen information on the forums before regarding it but I cant find it.

However, I have some code I'm trying to take from HL and move it to roll20.. And while this is a little off topic for a LoneWolf Forums but still..

The power attack code is:

Code:
      field[abValue].value += round(#BAB[]/4,0,-1) + 1
      field[abValue2].value += field[abValue].value * 2

Javascript doesn't seem to like Math.round(bab/4,0,-1) + 1 Anyone have an idea what the heck is going on?
 
Javascript doesn't use the multi-parameter rounding syntax. For the equivalent (which is truncating the result), use Math.floor(bab/4)
 
Thank you, that fixes things.

Out of curiosity and for future reference what do the other parameters do for the round() function do in HL?

So the third parameter, the "-1" means rounds down, aka the "floor()" function, and by extention a 1 would be round up or ceil(). What does the second parameter do? the "0" Is that a numeric base? or precision?
 
Thank you, that fixes things.

Out of curiosity and for future reference what do the other parameters do for the round() function do in HL?

So the third parameter, the "-1" means rounds down, aka the "floor()" function, and by extention a 1 would be round up or ceil(). What does the second parameter do? the "0" Is that a numeric base? or precision?

0 means use the normal rounding rules. If it's .5 or higher, round up; otherwise round down. So 4.5 rounds up to 5, and 4.4 rounds down to 4.
 
0 means use the normal rounding rules. If it's .5 or higher, round up; otherwise round down. So 4.5 rounds up to 5, and 4.4 rounds down to 4.

I believe he's asking about the 0 that's being used in the second parameter. That's for precision (i.e. number of decimal places to round to, which is usually zero for us because Pathfinder almost never deals in fractions).
 
Back
Top