Skip to main content
Participating Frequently
April 4, 2023
Answered

Conditional formatting for number field - either 2 or 4 decimal places

  • April 4, 2023
  • 2 replies
  • 1996 views

I have an Adobe form on which I would like the format of a field (“Recommended salary”) to be set to either 2 or 4 decimal places, depending on the value in another field (“FLSA Status”). If “FLSA Status = Exempt, I would like the format to be 2 decimal places and if “FLSA Status” = Non-exempt, I would like the format to be 4 decimal places.

Can anyone help me with the code for this? Also, what would I select as the format category for the “Recommended salary” field – Number? Ideally, the user would input something like this - $58,550.75 or $17.5214 depending on the FLSA Status.

This topic has been closed for replies.
Correct answer Nesa Nurani

Under 'Format' select 'Custom' and then as 'Custom format script' use this:

var status = this.getField("FLSA Status").valueAsString;
if(status == "Exempt")
event.value = util.printf("$%,0.2f",event.value);
else if(status == "Non-exempt")
event.value = util.printf("$%,0.4f",event.value);

2 replies

Participating Frequently
April 7, 2023

Hoping you can help me again. Management changed the FLSA Status field from a drop down to a radio button (2 choices - Exempt and Non-exempt. If the user doesn't select either option, they should not be able to enter any value into the Recommended Salary field at all. They would also like the numbers entered by the user to be truncated to 2 or 4 decimals instead of rounding. Would you be able to help me with the code for that? Thank you in advance.

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
April 4, 2023

Under 'Format' select 'Custom' and then as 'Custom format script' use this:

var status = this.getField("FLSA Status").valueAsString;
if(status == "Exempt")
event.value = util.printf("$%,0.2f",event.value);
else if(status == "Non-exempt")
event.value = util.printf("$%,0.4f",event.value);

Participating Frequently
April 7, 2023

Hoping you can help me again. Management changed the FLSA Status field from a drop down to a radio button (2 choices - Exempt and Non-exempt. If the user doesn't select either option, they should not be able to enter any value into the Recommended Salary field at all. They would also like the numbers entered by the user to be truncated to 2 or 4 decimals instead of rounding. Would you be able to help me with the code for that? Thank you in advance.

Nesa Nurani
Community Expert
April 7, 2023

Do you want to format as truncated, or you want actual value to be truncated?