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

NaN error

New Here ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

I have the following simple script in Custom calculation script in a Text Field called AS QUOTED CM%.

When the PDF Form has yet to be populated the AS QUOTED PROFIT field is $0 & the AS QUOTED TOTAL field is blank which creates a NaN answer. I want the calculated As QUOTED CM% field to be formated for Percent but I always get an error during use which will confuse the users.

How can I create an if NaN then 0 statement which I believe will resolve ther error

 

event.value =
(this.getField("AS QUOTED PROFIT").value/this.getField("AS QUOTED TOTAL").value)
;

 

TOPICS
PDF , PDF forms

Views

61

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 ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Check that "AS QUOTED TOTAL" is not 0 because you can't divide by zero, something like this:

if(this.getField("AS QUOTED TOTAL").value != 0)
event.value =
(this.getField("AS QUOTED PROFIT").value/this.getField("AS QUOTED TOTAL").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
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

LATEST

Dividing by zero returns Infinity.  When a field formatted as a number returns something other than a number it will display NaN ("Not a Number").  If you add the following script to the end of your script it will not only elimate the NaN display, but it will allow you to format the field as a percent and avoid popup "The value entered does not match the format..." errors:

if(event.value=="Infinity" || event.value=="NaN"){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