
Greetings all.
I have a calculation problem in the following sheetworker and I need some help with the solution syntax please...
on('change:body change:str change:con change:stunxp sheet:opened', function () {
getAttrs(['body','str','con','stunxp'], function(v) {
const body = v.body *1||0;
const str = v.str *1||0;
const con = v.con *1||0;
const stunxp = v.stunxp *1||0;
const stun = Math.round(body + str/2 + con/2 + stunxp);
setAttrs({
stun: stun,
stuncurrent_max: stun
});
});
});
My error is occurring with the "stun" value...
My input values are: "body"=10 "str"=11 "con"=11 "stunxp"=0
I am getting a final "stun" value of 21....it should be 22.
The error appears to be in the rounding...I believe the following calculation is occurring:
10 + 5.5 + 5.5 + 0 - 21
I need it to be:
10 + 6 + 6 + 0 = 22
In other words....the 11 / 2 needs to round...
How do I achieve this?
Thanks in advance...