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

Need negative number to show up as 0 on a calculated field

New Here ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Hello. I'm really new to this and am creating a form where I need to subtract Field B from Field A and make the total appear in Field C. This part I understand. The problem I'm running into is if the total equals a negative number, I want it to show up as zero. Is that possible? I've had a few other codes I've tried to just get it to display, but as soon as I do another formula within the pages, it makes the total disappear. If someone could please help with a good calculation code, I would really appreciate it!

TOPICS
How to

Views

1.1K

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 2 Correct answers

Community Expert , Dec 23, 2021 Dec 23, 2021

As validation script of FieldC use this:

if(event.value < 0)event.value = 0;

Votes

Translate

Translate
Community Expert , Jul 28, 2022 Jul 28, 2022

You can use this as 'Validation' script of "FieldA":

var num = Number(event.value);
if(num > 0){
this.getField("FieldB").value = 0;
this.getField("FieldC").value = "";}
else if(num < 0){
this.getField("FieldB").value = Math.abs(num);
this.getField("FieldC").value = Math.abs(num)/65;}
else{
this.getField("FieldB").value = "";
this.getField("FieldC").value = "";}

 

Votes

Translate

Translate
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

As validation script of FieldC use this:

if(event.value < 0)event.value = 0;

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
New Here ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

I've used that one, but how do I also make it calculate in the same field? I want Field C to do the math and also not to display anything negative.

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
New Here ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Nevermind! You're a genius!! It worked! I had been trying to put that code in the custom script for calculations!! Thank you so much!!!!

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 ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Along those lines, I am running into a challenge with an enrollment form I need help with.

I have a form field (FieldB) that needs to equal the value calculated in another field (FieldA) but ONLY if it’s a negative number, and then I want to convert it to a positive number. 

However, if the value of the other field (FieldA) is positive, I want field (FieldB) to display 0.

 

Finally, if FieldB is populated with a positive number, then I need FieldC to input with the FieldB divided by 65. Otherwise, FieldC will remain blank.

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 ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

You can use this as 'Validation' script of "FieldA":

var num = Number(event.value);
if(num > 0){
this.getField("FieldB").value = 0;
this.getField("FieldC").value = "";}
else if(num < 0){
this.getField("FieldB").value = Math.abs(num);
this.getField("FieldC").value = Math.abs(num)/65;}
else{
this.getField("FieldB").value = "";
this.getField("FieldC").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 Beginner ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

WOW, WOW, WOW!!! You are a genius.Works perfectly.

Thank you so much!! 

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
New Here ,
Oct 17, 2023 Oct 17, 2023

Copy link to clipboard

Copied

LATEST

Hi Nesa,

Thank you for that! That worked for one part of my form. My other issue is, i need to add two cells/fields but i need the result to only show "0" if the result is 0 or positive and the negative amount if the result is negative.

 

Appreciate any help you can provide!!! Thank you!

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