Skip to main content
Participant
February 18, 2025
Answered

Rounding calculation to a penny

  • February 18, 2025
  • 1 reply
  • 312 views

Hi,
Any help appreciated. Total noob by the way!
I am creating an invoice for agents to work out their commission on products sold. We pay them 50% on sale and 50% on delivery.

The form currently works up to the point of adding all products sold, applying their commission % and calculating total value of their commission ("Total_Commission").

I now want the invoice to show the two values of their first 50% ("SplitA") and second 50% ("SplitB") commissions.

The difficulty I have is with odd numbered commission totals.

For example, total commission = £100.05, if I include a calculation for SplitA in Simplified Field Notation: Total_Commission/2 I get £50.03. That's fine. The second commission invoice amount is now a problem as it needs to be £50.02. I have tried Total_Commission-SplitA in Simplified field notation, but it also produces £50.03.

It looks like I need to use a Custom Calculation Script, and I've tried several solutions, but am not having success!

Please help

Correct answer try67

As the calculation of the second commission field simply do the total minus the first commission field's value.

However, there might be an issue where the first field's value is actually not what it appears to be, due to rounding by the Format setting, so the actual value is "50.025" but it shows "50.03", for example.

To overcome that you would need to use a calculation script that actually rounds the value.

You can use something like this:

 

 

var v = Number(this.getField("Total_Commission").valueAsString)/2;
event.value = v.toFixed(2);

 

 

And then for the second field:

 

 

var v = Number(this.getField("Total_Commission").valueAsString)-Number(this.getField("SplitA").valueAsString);
event.value = v.toFixed(2);

 

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 18, 2025

As the calculation of the second commission field simply do the total minus the first commission field's value.

However, there might be an issue where the first field's value is actually not what it appears to be, due to rounding by the Format setting, so the actual value is "50.025" but it shows "50.03", for example.

To overcome that you would need to use a calculation script that actually rounds the value.

You can use something like this:

 

 

var v = Number(this.getField("Total_Commission").valueAsString)/2;
event.value = v.toFixed(2);

 

 

And then for the second field:

 

 

var v = Number(this.getField("Total_Commission").valueAsString)-Number(this.getField("SplitA").valueAsString);
event.value = v.toFixed(2);

 

 

Participant
February 18, 2025

Genius!! Thank you so much.