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

Getting field value 0 if the calue is grater than 0

Community Beginner ,
Mar 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

var J = Number(this.getField("V10").valueAsString);
var K = eval(this.getField("F10").valueAsString);
var d = Number(this.getField("H1").valueAsString);
var e = this.getField("D10").valueAsString;
var f = Number(this.getField("I1").valueAsString);

event.value = "";

if (e !== "") {
e = Number(e);
if (e === 0) {
event.value = "<LOD";
} else {
var total;
if (J !== 0 && f !== 0) {
total = (K * d) / (J * f);
event.value = total.toFixed(3);
}
}
}

Hi, 

in above script when I write 0/100 in K, the value appearing correct in E. But when I write 1/100 is F. Attached pdf link for file. 

Lab. 2.29.24_2 updated.pdf

TOPICS
JavaScript , PDF

Views

752

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

correct answers 1 Correct answer

Community Expert , Mar 13, 2024 Mar 13, 2024

Use another condition:

if (J == 0 && f == 0) {
total = (K * d);  ?

Votes

Translate

Translate
Community Expert ,
Mar 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

J7 is zero so the result of this formula is invalid (since division by zero is not allowed):

total = (K * d) / (J * f);

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 ,
Mar 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

can you tell me correct script to get the result. 

 

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 ,
Mar 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

What is the desired result in case J or F are zero?

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 ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

I require the calculation to produce a valid result even if the values of J and f are 0. The calculation should utilize the available fields to generate a meaningful outcome, rather than yielding an invalid result. Considering them as 1 might suffice, but I'm uncertain. I'm open to any solution that ensures the calculation behaves appropriately.

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 ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

There is no valid result in this scenario. The field should remain empty, in my opinion.

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 ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

I need the cell shows value. Is there any option we can achieve that?

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 ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

Use another condition:

if (J == 0 && f == 0) {
total = (K * d);  ?

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

Copy link to clipboard

Copied

Thanks it worked when I add this condition too with considering blank value as 1

 

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

Copy link to clipboard

Copied

LATEST

I used this 

var J = Number(this.getField("V1").valueAsString);
var K = eval(this.getField("F1").valueAsString);
var d = Number(this.getField("H1").valueAsString);
var e = this.getField("D1").valueAsString;
var f = Number(this.getField("I1").valueAsString);

event.value = "";

if (e !== "") {
e = Number(e);
var total;
if (J !== 0 && f !== 0) {
total = (K * d) / (J * f);
} else if (J === 0 && f === 0) {
total = K * d;
} else if (J === 0) {
total = (K * d) / f;
} else {
total = (K * d) / J; // If f is 0,
}
event.value = total.toFixed(3);
}

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

Copy link to clipboard

Copied

What value, exactly?

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