Skip to main content
Participating Frequently
December 23, 2021
解決済み

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

  • December 23, 2021
  • 返信数 1.
  • 2191 ビュー

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!

このトピックへの返信は締め切られました。
解決に役立った回答 Nesa Nurani

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

 

返信数 1

Nesa Nurani
Community Expert
Community Expert
December 23, 2021

As validation script of FieldC use this:

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

Participant
October 17, 2023

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!