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

Rounding by quarter decimals

Community Beginner ,
May 14, 2024 May 14, 2024

Copy link to clipboard

Copied

Can you help me with the following? In my Adobe fillable form, I want the output to be rounded to the nearest quarter hour, so in this case, 9.75.

INPUT (UnitsRow1): Enter Units per Month:  1,200

OUTPUT (AvgRow1): Average Hours Per Day: 9.86

  • Text field properties, Calculate. Simplified field notation: (UnitsRow1*12/365/4)

I also have the following Custom Format Script

if (event.target.value >= 10) {

    event.target.textColor = ["RGB", 255/255, 0, 0];

    }

else if (event.target.value <= 10) {

    event.target.textColor = ["RGB", 0, 0, 0];

}

var x = Number(event.value);

if(event.value)

event.value = x.toFixed(2) ;

And a custom validation script:

event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms

Views

340

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 ,
May 14, 2024 May 14, 2024

Copy link to clipboard

Copied

Instead of simplified field notation use custom calculation script:

var unitsPerMonth = Number(this.getField("UnitsRow1").value);
var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;

hoursPerDay = Math.round(hoursPerDay * 4) / 4;

event.value = hoursPerDay;

 

There is no need to have both custom format and validation scripts for text color.

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 Beginner ,
May 15, 2024 May 15, 2024

Copy link to clipboard

Copied

Thank you very much for your time and help; I appreciate it.

 

To round AvgRow1 (and AvgRow2 and AvgRow2) to the nearest quarter hour, I changed the simplified field notation to the custom calculation script you provided, which worked. However, several more calculated fields are on the form, and this negatively affects OutcomeRow1, OutcomeRow2, and OutcomeRow3. I tried changing the Text field properties for OutcomeRow1, 2, and 3 to var v1, var v2, and var v3, but it didn’t seem to fix the issue. What am I missing?

 

ABC Eligibility Calculation

UnitsRow1: Enter Units per Month:  1,200

AvgRow1: Average Hours Per Day: 9.86

  • Text field properties

Format. Custom Format Script:

if (event.target.value >= 10) {

    event.target.textColor = ["RGB", 255/255, 0, 0];

    }

else if (event.target.value <= 10) {

    event.target.textColor = ["RGB", 0, 0, 0];

}

var x = Number(event.value);

if(event.value)

event.value = x.toFixed(2) ;

 

Validate. Hours not to exceed 10 per day. Run custom validation script:

event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;

 

Calculate. Custom calculation script:

var unitsPerMonth = Number(this.getField("UnitsRow1").value);

var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;

hoursPerDay = Math.round(hoursPerDay * 4) / 4;

event.value = hoursPerDay;

 

OutcomeRow1:

  • Text field properties

Calculate. Custom calculation script:

var v1 = Number(this.getField("AvgRow1").valueAsString);

event.value = (v1>=1) ? "Qualifies for ABC, provides one or more hours of service per day." : "Does NOT qualify for ABC, provides less than one hour of service per day.";

 

CDE Eligibility Calculation

UnitsRow2: Enter Units per Month: 1,000

AvgRow2: Average Hours Per Day: 8.25

  • Text field properties,

Format. Custom Format Script:

if (event.target.value >= 10) {

    event.target.textColor = ["RGB", 255/255, 0, 0];

    }

else if (event.target.value <= 10) {

    event.target.textColor = ["RGB", 0, 0, 0];

}

var x = Number(event.value);

if(event.value)

event.value = x.toFixed(2) ;

 

Validate. Hours not to exceed 10 per day. Run custom validation script:

event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;

 

Calculate. Custom calculation script:

var unitsPerMonth = Number(this.getField("UnitsRow2").value);

var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;

hoursPerDay = Math.round(hoursPerDay * 4) / 4;

event.value = hoursPerDay;

 

 OutcomeRow2:

  • Text field properties.

Calculate. Custom calculation script:

var v1 = Number(this.getField("AvgRow2").valueAsString);

event.value = (v1>=3) ? "Qualifies for CDE, provides three or more hours of service per day." : "Does NOT qualify for CDE, provides less than three hours of service per day.";

 

EFG Eligibility Calculation

UnitsRow3: Enter Units per Month: 1,000

AvgRow3: Average Hours Per Day: 8.25

  • Text field properties

Format. Custom Format Script:

if (event.target.value >= 10) {

    event.target.textColor = ["RGB", 255/255, 0, 0];

    }

else if (event.target.value <= 10) {

    event.target.textColor = ["RGB", 0, 0, 0];

}

var x = Number(event.value);

if(event.value)

event.value = x.toFixed(2) ;

 

Validate. Hours not to exceed 10 per day. Run custom validation script:

event.target.textColor = (event.value > 10 || event.value < 10) ? color.black : color.red;

 

Calculate. Custom calculation script:

var unitsPerMonth = Number(this.getField("UnitsRow3").value);

var hoursPerDay = (unitsPerMonth * 12) / 365 / 4;

hoursPerDay = Math.round(hoursPerDay * 4) / 4;

event.value = hoursPerDay;

 

OutcomeRow3:

  • Text field properties

Calculate. Custom calculation script:

var v1 = Number(this.getField("AvgRow3").valueAsString);

event.value = (v1>=1) ? "Qualifies for EFG, provides one or more hours of care per day." : "Does NOT qualify for EFG, provides less than one hour of service per day.";

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 ,
May 15, 2024 May 15, 2024

Copy link to clipboard

Copied

It didn't affect other fields, your field calculation order is not correct, select 'Prepare form' tool, then click on 'More' then select 'Set field calculation order', OutcomeRow fields should be under Avg fields:

Wrong:                                                                                   Correct:

Izrezak.PNGIzrezak1.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
Community Beginner ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

LATEST

Thank you so very much.  :tulip::sun_with_face:

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