Skip to main content
rubenm2021
Participant
March 27, 2016
Answered

Change positive number to Negative

  • March 27, 2016
  • 2 replies
  • 4692 views

Hello,

I am using the SUM function in calculated field to add and subtract values and display the results in a "Total" field.  In order to make the subtraction work, the user has to enter a negative number in the "Losses" field.  I would like to have the user just enter a number and have the field automatically change it to a negative number.  Is there a way to do this, or should I be approaching this in a different way?

This topic has been closed for replies.
Correct answer gkaiseril

A negative number in a column where the color (sign) is negative would indicate a positive number.

I would perform the calculation using the subtract operator. This can be done in the Simplified or the Custom JavaScript options.

2 replies

gkaiserilCorrect answer
Inspiring
March 27, 2016

A negative number in a column where the color (sign) is negative would indicate a positive number.

I would perform the calculation using the subtract operator. This can be done in the Simplified or the Custom JavaScript options.

rubenm2021
Participant
March 27, 2016

Thank you.  I found a video online that explained how to simply add and subtract fields in the Simplified Java Script option.

Thanks.

Inspiring
March 28, 2016

OK, but consider what would happen if the user enters a negative number.

Inspiring
March 27, 2016

You can use a custom validate script to automatically make any positive numbers negative, something like:

// Custom Validate script for text field

// If the entered value when converted to a number is greater than zero...

if (+event.value > 0) {

    // ...multiply it by -1 to convert it to a negative number

    event.value = -1 * event.value;

}

rubenm2021
Participant
March 27, 2016

Thank you for your quick response.  You solution would definitely work, but I decided to use the Simplified function in the Calculated tab. Thanks