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

Custom calculation getting incorrect results with blank fields

New Here ,
Jan 09, 2025 Jan 09, 2025

Copy link to clipboard

Copied

We have the following custom calculation script:

 

event.value = ( this.getField("Food Minimum").value + this.getField("Lunch Minimum").value + this.getField("Service Charge").value ) * ( this.getField("Food Service Tax %").value );

 

The problem occurs when Food minimum or Lunch Minimum are blank (no data), the calculation multiplies the value of the non-blank field, circumstantially. 

if Lunch Min is blank, and you enter a value of $1 in Food Min, it will calculate as $10 (one dec place)

if Lunch Min is blank, and you enter a value of $10 in Food Min, it will calculate as $100 (one dec place)

if Lunch Min is blank, and you enter a value of $100 in Food Min, it will calculate as $10000 (2 dec places)

if Lunch Min is blank, and you enter a value of $1000 in Food Min, it will calculate as $1,000,000 (3 places)

..up to a value of 4166 ..  enter value 4167 and the calculation will now go to 4 decimal places (41,670,000)

 

*if you reverse and leave Food Min blank instead, then Lunch Min seems to calculate x 10 with any value (one dec place shift)

 

any explanation or guidance would be great.  The answer is to make sure there's a "0.00" value rather than a blank field and then it calculates properly.

 

thanks

 

TOPICS
Edit and convert PDFs , PDF forms

Views

23

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 ,
Jan 09, 2025 Jan 09, 2025

Copy link to clipboard

Copied

LATEST

I sounds like it is concatenating the numbers instead of adding them.  In JavaScript, the + sign can be used for addition or concatenation (putting strings together).  If the JavaScript engine interprets any part of the addition equation as a string it will concatenate (100+100 = 100100 instead of 200).  Are your fields formatted as numbers?  This should take care of the issue.  Or you can use the Number method like this:

Number(this.getField("Food Minimum").value) + Number(this.getField("Lunch Minimum").value) + Number(this.getField("Service Charge").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