Formulas - Multiplying a value by -1 always gives back -1 as an answer.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • axyl
    Member
    • Jun 2021
    • 32

    Formulas - Multiplying a value by -1 always gives back -1 as an answer.

    In a formula, if you multiply a value by a negative number, the answer is always the negative number you used.

    $value= (20 * -10);
    output\printLine($value);​

    Returns -10;

    $value= (20 * -1);
    output\printLine($value);​

    Returns -1;

    Do other people get this too? Confirm it in the Formula Sandbox.

    Version 8.2.2​
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Use parentheses. * (-10)
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • ThomasB
      Senior Member
      • Mar 2022
      • 163

      #3
      I think we had a similar bug report about this.

      Use this as workaround:

      $value= (20 * (-10));
      output\printLine($value);​

      Comment

      • shalmaxb
        Senior Member
        • Mar 2015
        • 1602

        #4
        these work both

        [your field] = -(20*10)

        [your field]= 20*(-10);​

        Comment

        Working...