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

Decimal places in "calculated" field

Explorer ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

I searched through some other posts and can't figure out how to apply the answers to my situation.  

 

I have a detailed form.  Three of the fields towards the end of the form are:  Subtotal (which adds up 8 fields above); Plus5 (which calculates a 5% cushion on the Subtotal field); Total (which adds together Subtotal and Plus5.  

31578672014z_2-1699560141161.png

 

These calculations and formats (decimal places, etc.) are correct and I'm not having any trouble with those.

 

Then I have a Summary field which pulls in text and data from all the above fields that looks like this:

Conference Registration $ 500
Lodging $ 251.56 X 3 = $ 754.68

Out-of-State Total $ 1254.68
Plus 5% (In-State Only) $ 62.73400000000001
In-State Total $ 1317.414

 

This is a custom script that looks in part like this:

event.value = "Conference Registration  $ " + this.getField("ConfRegFee").value +

"\nLodging  $ " + this.getField("HotelCost").value + " X " + this.getField("HotelNights").value + " = $ " + this.getField("HotelTotal").value +

........ +
"\nOut-of-State Total $ " + this.getField("OOSTotal").value +
"\nPlus 5% (In-State Only) $ " + this.getField("Plus5").value + "\nIn-State Total $ " + this.getField("ISTotal").value

 

 

I have two questions.  

1) How do I get the Conference Registration line to show in the Summary with 2 decimal places?

2) How do I get the Plus 5% and the In-State Totals to round to 2 decimal places?

 

I'm thinking it has something to do with not formatting the fields as $, but as numbers with 2 decimals....  But, I can't seem to get that to work either..

 

Any assistance is appreciated!

Thanks,

Ruth

 

TOPICS
PDF forms

Views

690

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 ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

If you format the field as a number with two decimals also select currency sign and remove it from your script then.

If you wish to use script, you can use toFixed(2) to format value to two decimal places.

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 ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

I'm sorry, but could you explain the currency change in more detail?

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 ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

When you format the field, you can also select currency:

tempsnip.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
New Here ,
Nov 10, 2023 Nov 10, 2023

Copy link to clipboard

Copied

thx!

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 ,
Nov 10, 2023 Nov 10, 2023

Copy link to clipboard

Copied

Thank you!  I think I've got it working.  The last part of my script looks like this now:

"\nOut-of-State Total $ " + this.getField("OOSTotal").value.toFixed(2) +
"\nPlus 5% (In-State Only) $ " + this.getField("Plus5").value.toFixed(2) +

"\nIn-State Total $ " + this.getField("ISTotal").value.toFixed(2)

 

But, I seem to have a new problem...

 

Now, the only issue is that the results only seem to show up after all the fields are completed.  But, the problem is that most times not all the the fields will be used.

 

I need the Summary to show up regardless, but the places where the are no charges will be empty.....

 

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 ,
Nov 10, 2023 Nov 10, 2023

Copy link to clipboard

Copied

LATEST

Use this:

 

var str = [
{fields: "OOSTotal", text: "Out-of-State Total $ "},
{fields: "Plus5", text: "\nPlus 5% (In-State Only) $ "},
{fields: "ISTotal", text: "\nIn-State Total $ "}];

var cText = "";
for(var i in str){
var fieldValue = this.getField(str[i].fields).value;
if(typeof fieldValue === "number" && !isNaN(fieldValue) && fieldValue !== 0)
cText += str[i].text + fieldValue.toFixed(2);}

event.value = cText;

 

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