Skip to main content
Dorothy26138473siql
Known Participant
May 6, 2024
Question

Problem with my calculations

  • May 6, 2024
  • 1 reply
  • 6731 views

Hello, I am having some problems with the calculations for our GST on my form. The GST 50 column should take the GST from gst.1 divide by half first and then round down second. It only needs to round down if the number is not perfectly divisible by 2 though. so if I enter 16.06 which is an even number, as the GST it should round to 8.03 but its not, its rounding down to 8.02.  If I have say 5.27 that isn't easily divisible, the government pays the lower half, we pay the higher half, so I need that to round down to 2.62. 

 

I had to redo my calculations for the Receipt total, GST on receipt  km $ and Total meals columns to the sum method,  but it seems to have broken my calculation script and validation script when i did that. I have attached the file. 

 

Any assistance would be amazing!

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 6, 2024

After rounding the number to two decimals you can multiple it by 2. If the result doesn't equal the original value (because it's an "odd" number that was rounded) then reduce 0.01 from it.

Dorothy26138473siql
Known Participant
May 6, 2024

Thank you, however, I don't know exactly how to do that Lol this script was written for me, I am only just starting to learn javascript.

try67
Community Expert
Community Expert
May 6, 2024

Try this:

 

var gst = Number(this.getField("gst.1").valueAsString);
var gsthalf = roundDown(gst / 2, 2);
if ((gsthalf*2)!=gst) {
	gsthalf-=0.01;
}

function roundDown(v, nDecimals) {
	return Math.floor(v * Math.pow(10, nDecimals)) / Math.pow(10, nDecimals);
}