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

javascript calculations x 150 =

New Here ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

I'm trying to figure out what the format would be for the following calculation

 

I'm taking the number in text1.0.1 multiplied by 150 and getting the pardons in field text 2   as a 4 digit number

lindac27335921_0-1650330786774.jpeg

i need to take the number in text1.0.1 25,950,075.0 x 150 = 3,893,711,250

now i only need the first 4 numbers in the answer 3893 to post in text2  the 1st box under pardons.

 

here is the calculation box -

lindac27335921_1-1650331087708.jpeg

which box do I use and what is the javascript that I put in the edit box when I open it.

 

once I get the correct format, I can just copy that format down to the other pardon fields and change the first field box and all else should work

 

all help would be great appreciated

Ms Linda

 

TOPICS
JavaScript

Views

395

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 ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

Use 'Custom calculation script' box of "Text2" field, and put this inside:

var num = Number(this.getField("Text1.0.1").valueAsString)*150;
var str = num.toString().slice(0,4);
if(str.length == 4)
event.value = str;
else
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
New Here ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Thank you so very much and with that calculation script, i was able to complete the form for 7 fields just by changing the text box number it was completed in a matter of minutes and all the numbers worked perfectly.

 

thank you again for your assistance

Ms Linda

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
New Here ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

I followed your directions and it worked on the 4 with 10 15 20 25 million but with I went under 10 million the answers doubled> not sure why using the same formula as it was taking the firs 4 numbers and not the first 3 and then when lower it should have taken the first 2 to keep the form in sync. What needs to be added to the formula to make the variable work to get the correct answer?



Here is the form



Look at the comments on the form.



Thank you for your assistance.



Mslinda





Sent from Mail for Windows

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Post script you used for lower numbers.

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
New Here ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

i used the same script that you gave me before .. and just plugged in the numbers below 10,000,000   

 

and got the numbers on the form    if you look at the form you will see what i did 

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

LATEST

Use this:

var f = this.getField("Text1.1.1").valueAsString;
var num = Number(f)*150;
var str = num.toString();
if(f.length >= 8)
event.value = str.slice(0,4);
else if(f.length == 7)
event.value = str.slice(0,3);
else if(f.length == 6)
event.value = str.slice(0,2);
else if(f == "")
event.value = "";

 

It will  work for all fields with values between 100,000-999,999 2 digits, 1,000,000-9,999,999 3 digits,10,000,000 and above 4 digits, you can easily adapt it( e.g. number less than 100,000) if needed.

When using in other fields just change field name in script.

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