javascript - Round up if positive, round down if negative? -


i'm trying make following figures true:

etc 5 = -2 6 = -1 7 = -1 8 = 0 9 = +1 10 = +1 11 = +2 

and on.

what i'm using right :

function abilitymodifier( n) {     return math.round( (n-8) /2); }      

which returns correct positive figures, makes 7 = 0, 6 = -1, 5 = -1, etc. wrong.

is there better formula using? bare in mind i'm using nbos character sheet designer.

function abilitymodifier(n) {     var x = n - 8;     if (x > 0)         return math.ceil(x / 2);     return math.floor(x / 2); }      

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -