• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
7

Problem with my calculations

Explorer ,
May 06, 2024 May 06, 2024

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!

TOPICS
General troubleshooting , How to , JavaScript , PDF , PDF forms

Views

654

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2024 May 06, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2024 May 06, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2024 May 06, 2024

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);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

so that worked for the even one, but not the odd, its rounding up instead of down....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Not for me... I entered 5.27 and it returned 2.62.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Dorothy26138473siql_0-1715034883041.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Can you share the new file?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Here you go, I only changed the one in the first line. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2024 May 07, 2024

Copy link to clipboard

Copied

I don't see the code I provided in this file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 07, 2024 May 07, 2024

Copy link to clipboard

Copied

GSThalf1 has the new code in the custom validation script. and it has this as the calculation script. 

 

event.value = Number(this.getField("gst.1").valueAsString) / 2;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2024 May 07, 2024

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 07, 2024 May 07, 2024

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 07, 2024 May 07, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2024 May 07, 2024

Copy link to clipboard

Copied

Again, you need to share the file for help... Also, set the field's Format setting to None.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 07, 2024 May 07, 2024

Copy link to clipboard

Copied

My apologies, here is the form. I did have this in the format box, to prevent the 0 from being in the field 

 

if((event.value == 0) || isNaN(event.value) || (event.value == Infinity))
event.value = "";
else
event.value = util.printf("$%,0.2f",event.value);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2024 May 08, 2024

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

When you enter 5.27 what should be result for you and what result for government?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2024 May 08, 2024

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2024 May 08, 2024

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2024 May 08, 2024

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!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

Would these values be correct?

Izrezak.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

Yes!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2024 May 08, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2024 May 08, 2024

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines