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.
Copy link to clipboard
Copied
The result of 5*0.5*2 is 5, not 4.
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".
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.
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);
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.