3 Replies Latest reply: Oct 31, 2013 11:38 AM by Hugo Sheng RSS

    negative wages

      Hello,

        This code  is not producing a negative wage when the .csv contains one.  Help.

      Thanks Traci

      local wages = string.allow(input.EMPLOYEE_WAGES,'-01234567890.');

      log.notice(wages);

       

      local mswtd=todecimal(wages);

      if (mswtd~=nil and mswtd~=0) then output.WageAmount = mswtd; end;

        • Re: negative wages

          Are you certain that the minus sign in the listing of allowed characters is the same character as a minus sign in your data?  If not, the string.allow function will be removing the minus sign.

           

          What value is printed for the log.notice call?  Does it still include minus sign?

           

          What value would be printed if you displayed the value in mswtd?  Is this value negative when appropriate?

           

          Your code should actually test for a nil value before you use string.allow, then there would be no need for the if statement.

          • Re: negative wages
            Paul Madden

            What kind of output are you getting?  When I try your code, I get garbage data whether EMPLOYEE_WAGES is positive or negative.

             

            Also, are you just trying to convert EMPLOYEE_WAGES to a decimal?  Or is there something else you are trying to accomplish?

            • Re: negative wages
              Hugo Sheng

              I tried running your logic natively in datascript and was able to retain the minus sign:

               

              C:\Program Files (x86)\expressor\expressor3\bin>datascript
              QlikView Expressor datascript utility (datascript) 3.9.1.24933 n (Build 24933) May  2 2013
              Copyright (C) 2003-2012 expressor software corporation
              > EMPLOYEE_WAGES='-123.45'
              > wages = string.allow(EMPLOYEE_WAGES,'-01234567890.');
              > print(wages);
              -123.45
              >
              > mswtd=todecimal(wages);
              > if (mswtd~=nil and mswtd~=0) then WageAmount = mswtd; end;
              > print(WageAmount)
              -123.45
              >