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

Getting field value 0 if the calue is grater than 0

Community Beginner ,
Mar 12, 2024 Mar 12, 2024

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
1.5K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 13, 2024 Mar 13, 2024

Use another condition:

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

View solution in original post

Translate
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

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

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

Translate
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

can you tell me correct script to get the result. 

 

Translate
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

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

Translate
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

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.

Translate
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

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

Translate
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

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

Translate
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

Use another condition:

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

Translate
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

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

 

Translate
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
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);
}

Translate
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

What value, exactly?

Translate
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