Copy link to clipboard
Copied
hi, I'm using bellow script. my issue is if i do calculation separately with round up, result is not same. so i want edit my script get roundup total like bellow.
event.value = (this.getField("Tax").value / 100) * this.getField("M0").value;
event.value = (event.value <= 0)?"":event.value;
"Tax" field - 8.25%
"M0" = (J0 +K0 +L0)
so i want to do calculation like bellow.
(J0 * 8.25/100) = Result round up to two decimal places
(K0 * 8.25/100) = Result round up to two decimal places
(K0 * 8.25/100) = Result round up to two decimal places
And get total off above all 3 values.
Hope my explanation is clear & some can help me. thanks..
Copy link to clipboard
Copied
None of the calculations you show will round up to two decimal places. If you display only two places, it will round in general (down or up), so in order to always round up, you will have to do an extra step. The following function will always round up to two decimal places:
function round_up(n) {
return Math.ceil(n*100)/100;
}
With that, you can then calculate your total based on the three individual results. The only remaining question is if you want to round the numbers J0, K0 and M0 to the desired resolution, or if you want to round the sum of these numbers, or the sum of the calculated percentages.
Copy link to clipboard
Copied
hi, thanks a lot for your answer. i will explain my issue using two example values so u can get some idea.. pls help me get updated code. thanks again..
Tax = 8.25
J0 = 1191
K0 = 99
If we add above values then my script giving bellow answer
1194 + 99 = 1293 * 8.25% = 106.67
But i need it giving answer like bellow
1194 x 8.25 = 98.51
99 * 8.25% = 8.17
Total = 106.68
Copy link to clipboard
Copied
So, what you want is for the field values to be the actual calculated value, but the user display to show the rounded value.
This is the purpose of field formatting.
Do this:
1) Do not round any of the Calculation results. Make all the calculations return the natural result.
2) Set the field formatting to show two decimal places.
Done!
Copy link to clipboard
Copied
sorry it didn't work..
Copy link to clipboard
Copied
Use the function round_up
Copy link to clipboard
Copied
hi, thanks. is that possible to explain it little more ?? if u can give code s code that will be big help to me. thanks..
Copy link to clipboard
Copied
hi, thanks. finally i have managed it. thanks..
var v1 = Math.round(((this.getField("Tax").value / 100) * this.getField("J0").value)*100)/100;
var v2 = Math.round(((this.getField("Tax").value / 100) * this.getField("K0").value)*100)/100;
var v3 = Math.round(((this.getField("Tax").value / 100) * this.getField("L0").value)*100)/100;
event.value = v1 + v2 + v3;
event.value = (event.value <= 0)?"":event.value;