Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Return negative number as 0

Return negative number as 0

Scheduled Pinned Locked Moved JavaScript
csshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    and180y
    wrote on last edited by
    #1

    Hi, first time posting so hopefully doing it correctly. I have used a form builder to build my forms but have run into a couple of issues with functionality. In the code/calculation below I need to be able to return the answer 0 if the answer is less than 0. I've searched loads to no avail so any help would be much appreciated. T.I.A.

    $('form#Commission #Commission_On').formCalc(" Nett_Earnings -Actual_Takings >0==0",{ currency_format:true, mirror:'sfm_Commission_On_parsed'});

    L Richard DeemingR 2 Replies Last reply
    0
    • A and180y

      Hi, first time posting so hopefully doing it correctly. I have used a form builder to build my forms but have run into a couple of issues with functionality. In the code/calculation below I need to be able to return the answer 0 if the answer is less than 0. I've searched loads to no avail so any help would be much appreciated. T.I.A.

      $('form#Commission #Commission_On').formCalc(" Nett_Earnings -Actual_Takings >0==0",{ currency_format:true, mirror:'sfm_Commission_On_parsed'});

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You still have the same problem that the expression Nett_Earnings -Actual_Takings >0==0 does not make a lot of sense. The > operator means greater than, and == means equals. You need to capture the value of Nett_Earnings -Actual_Takings and then set it to zero if it is negative (assuming I understand the question).

      A 1 Reply Last reply
      0
      • L Lost User

        You still have the same problem that the expression Nett_Earnings -Actual_Takings >0==0 does not make a lot of sense. The > operator means greater than, and == means equals. You need to capture the value of Nett_Earnings -Actual_Takings and then set it to zero if it is negative (assuming I understand the question).

        A Offline
        A Offline
        and180y
        wrote on last edited by
        #3

        Thanks for replying. I'm struggling to get to the point of showing 0. Is this more like what I should have Nett_Earnings-Actual_Takings=Value<0=0 Does the script generate Value?

        L 1 Reply Last reply
        0
        • A and180y

          Thanks for replying. I'm struggling to get to the point of showing 0. Is this more like what I should have Nett_Earnings-Actual_Takings=Value<0=0 Does the script generate Value?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          No, that is still not a valid expression. I think you need to do one or both of two things: 1. Learn Javascript, expecially with regard to expressions and operators. 2. Find out exactly how this package that you are trying to use actually works. It may well be that it uses different syntax from Javascript so anything mentioned here may not be valid.

          1 Reply Last reply
          0
          • A and180y

            Hi, first time posting so hopefully doing it correctly. I have used a form builder to build my forms but have run into a couple of issues with functionality. In the code/calculation below I need to be able to return the answer 0 if the answer is less than 0. I've searched loads to no avail so any help would be much appreciated. T.I.A.

            $('form#Commission #Commission_On').formCalc(" Nett_Earnings -Actual_Takings >0==0",{ currency_format:true, mirror:'sfm_Commission_On_parsed'});

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Looking at the documentation, you need to modify your calculation to use either an if_else expression:

            $('form#Commission #Commission_On').formCalc("if_else(Nett_Earnings > Actual_Takings, Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });

            or the max function:

            $('form#Commission #Commission_On').formCalc("max(Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });

            Calculation field : function reference| Simfatic Forms 5.0 Help[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            A 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              Looking at the documentation, you need to modify your calculation to use either an if_else expression:

              $('form#Commission #Commission_On').formCalc("if_else(Nett_Earnings > Actual_Takings, Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });

              or the max function:

              $('form#Commission #Commission_On').formCalc("max(Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });

              Calculation field : function reference| Simfatic Forms 5.0 Help[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              A Offline
              A Offline
              and180y
              wrote on last edited by
              #6

              Thanks Richard, top code worked perfectly. :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups