• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Need negative number to show up as 0 on a calculat...

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

New Here ,
Dec 23, 2021 Dec 23, 2021

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

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

As validation script of FieldC use this:

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

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 = "";}``````

7 Replies 7
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Copied

As validation script of FieldC use this:

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

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Dec 23, 2021 Dec 23, 2021

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.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Dec 23, 2021 Dec 23, 2021

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!!!!

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

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.

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

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 = "";}``````

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 Beginner ,
Jul 29, 2022 Jul 29, 2022

Copied

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

Thank you so much!!

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Oct 17, 2023 Oct 17, 2023

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.