Oops on the Math.floor script missed something important

Community Beginner ,
Apr 21, 2019

Copy link to clipboard

Copied

Hi all,

You helped me tremendously with this script earlier, but I found one error I made I have to halve the first field and use the mathfloor here before continuing operations. I thought it was an easy fix and may be, but I am missing it. This is the change I made.

event.value = Math.floor(Number(this.getField("g1p1resources").valueAsString)  * 0.5 * Number(this.getField("g1p1multiple1").valueAsString)); 

I moved the *.05 from the end to just after the first statement. Running it through the console it says it is right, but the calculation for example for 5*.5*2 comes up 5 when it should be returning 4

5 halved is 2.5 rounded down to 2 * 2 = 4

I am really rusty on my javascript haven't used it in years and trying to get back in is proving to be a bear. Thank you for your help.

TOPICS
Acrobat SDK and JavaScript

Views

389

Likes

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

Oops on the Math.floor script missed something important

Community Beginner ,
Apr 21, 2019

Copy link to clipboard

Copied

Hi all,

You helped me tremendously with this script earlier, but I found one error I made I have to halve the first field and use the mathfloor here before continuing operations. I thought it was an easy fix and may be, but I am missing it. This is the change I made.

event.value = Math.floor(Number(this.getField("g1p1resources").valueAsString)  * 0.5 * Number(this.getField("g1p1multiple1").valueAsString)); 

I moved the *.05 from the end to just after the first statement. Running it through the console it says it is right, but the calculation for example for 5*.5*2 comes up 5 when it should be returning 4

5 halved is 2.5 rounded down to 2 * 2 = 4

I am really rusty on my javascript haven't used it in years and trying to get back in is proving to be a bear. Thank you for your help.

TOPICS
Acrobat SDK and JavaScript

Views

390

Likes

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
Apr 21, 2019 0
Adobe Community Professional ,
Apr 21, 2019

Copy link to clipboard

Copied

The result of 5*0.5*2 is 5, not 4.

Likes

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
Reply
Loading...
Apr 21, 2019 0
Most Valuable Participant ,
Apr 21, 2019

Copy link to clipboard

Copied

The question is what you want to use the floor function on. Is it just the value of "g1p1resources" times 0.5, or the entire operation (as I understood earlier). If it's the former you need to move the closing parentheses of the floor command before multiplying by the value of "g1p1multiple1".

Likes

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
Reply
Loading...
Apr 21, 2019 0
Community Beginner ,
Apr 21, 2019

Copy link to clipboard

Copied

I want to use the math floor on the g1p1resources times ,5. For example if they have 5 it is halved to 2.5 and then rounded down to 2 before the final multiplication which would make it 2 times whatever the multiplier is.

Thanks for your help on this.

Likes

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
Reply
Loading...
Apr 21, 2019 0
Most Valuable Participant ,
Apr 21, 2019

Copy link to clipboard

Copied

OK, that was not clear from your original question (by the way, in the future please post follow-ups under the original thread, instead of in a new one). To do it use this code:

event.value = Math.floor(Number(this.getField("g1p1resources").valueAsString) * 0.5) * Number(this.getField("g1p1multiple1").valueAsString);

Likes

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
Reply
Loading...
Apr 21, 2019 0
Community Beginner ,
Apr 21, 2019

Copy link to clipboard

Copied

Thank you for the help. Sorry on the new post I wasn't sure whether or not to continue there or if it was closed when resolved.

Take care.

Likes

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
Reply
Loading...
Apr 21, 2019 0