Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
so that worked for the even one, but not the odd, its rounding up instead of down....
Copy link to clipboard
Copied
Not for me... I entered 5.27 and it returned 2.62.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Can you share the new file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I don't see the code I provided in this file.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Why a validation script? It needs to replace your current calculation script.
Just add this to the end of it:
event.value = gsthalf;
Copy link to clipboard
Copied
haha because i totally thought it was a validation script, likle i said i am still learning! This seems to be working 🙂
Thank you so much for your help and putting up with me!
Copy link to clipboard
Copied
so, i spoke too soon, when i put a round number in, like says 16.06 its making it 8.01
Copy link to clipboard
Copied
Again, you need to share the file for help... Also, set the field's Format setting to None.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi not sure if you saw my last message? I do very much appreciate you helping me out, I go on vacation after tomorrow and my boss is standing at my desk asking me if I know what i am doing LOL which i obviously dont!
Copy link to clipboard
Copied
When you enter 5.27 what should be result for you and what result for government?
Copy link to clipboard
Copied
so if the amount is even, say .06 it should be .03 each. If the amount is odd, .23 or .27 etc , ours needs to be the rounded up, government is rounded down. So .27 is .12 for government and .13 for us, .23 is .11 for governemnt .12 for us.
Copy link to clipboard
Copied
That doesn't sound correct, if you have 5.27, you say government pay 2.62, and you pay 2.63?
That equals to 5.25, so where are 2 cents went?
Shouldn't correct result be government 2.63 and you 2.64?
Copy link to clipboard
Copied
obviously my math skills arent up to snuff this morning! sorry. 5.27 would be 2.63 and 2.64 we pay the 2.64
Sorry!!
Copy link to clipboard
Copied
Would these values be correct?
Copy link to clipboard
Copied
Yes!!
Copy link to clipboard
Copied
Test fields and check if they all works correctly.
https://drive.google.com/file/d/16KUltG4YUcrto3hDyY4CwHD93I8Dl1To/view?usp=sharing
If you need to know all the changes I have made, let me know, and I will send you PM with description of changes.
Copy link to clipboard
Copied
So this is good the only thing i see that is a problem now is that the program costs at the end, that needs to add up receipt total, km$ Total MEals and GST
it was this
var gst = Number(this.getField("gst.1").valueAsString);
var rectotal = Number(this.getField("rec.1").valueAsString);
var km = Number(this.getField("km.1").valueAsString);
var meals = Number(this.getField("meal.1").valueAsString);
var v = gst / 2;
var nDecimals = 2;
var gsthalf = Math.ceil(v * Math.pow(10, nDecimals)) / Math.pow(10, nDecimals);
event.value = (rectotal-gst)+km+meals+gsthalf;
can i just put that back in myself?