Formatting negative number

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Formatting negative number

  • Creator
    Topic
  • #51842
    Mike Campbell
    Participant

      Here is an interesting one.

      I have an incoming vrl file that has payment information.

    Viewing 7 reply threads
    • Author
      Replies
      • #71952
        John Mercogliano
        Participant

          Mike,

          John Mercogliano
          Semi Retired, contractor
          Hampton Roads, VA

        • #71953
          Mike Campbell
          Participant

            I did remove the dash from the subsub field.  

            The actual payment data does have the parenthesis around the ‘negative’

            amount.  I’m trying to structure a lsearch or lindex command to let me know

            that the “(” exists but haven’t had any success with that.

          • #71954
            Jim Kosloskey
            Participant

              Mike,

              Once you have the value out if the xlateInVals list into a variable, you can do a number of things to determine if the parens exist.

              one way is a regexp (I will let you ty that if you want).

              another way is to simple use an if  with ‘string range’ to check the first character to see if it is “(” (the assumption here is that if the field begins with the left paren it probably ends with the right paren). If the assumption is more than what you want to make, then you can also check the last charactre for a right paren.

              In any case, you will most likely also need to remove the parens – the ‘string map’ command can accomplish that for you – or you can use regsub.

              email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 61 years IT – old fart.

            • #71955
              John Mercogliano
              Participant

                In that case it sounds like they are sending negative amounts as (##.##) .  A simple string map could be the trick.  

                Code:


                lassign $xlateInVals payment
                set payment [string trim [string map {( – ) {}} $payment]]
                set in_length [clength $payment]
                set xlateOutVals [list [format “%0$in_length.2f” $payment]]

                John Mercogliano
                Semi Retired, contractor
                Hampton Roads, VA

              • #71956
                Jim Kosloskey
                Participant

                  That too  😮

                  email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 61 years IT – old fart.

                • #71957
                  Mike Campbell
                  Participant

                    Thanks to the good ideas, I’m much closer…

                    I am able to check for the existance of the ( and can do the

                    trim to format the output.

                    Now, just to add an explicit negative sign to the front of the amount.

                    So:

                     incoming (76)

                     otubound  -76.00

                    I’m thinking the concat command should work.

                    Gotta love vendors!

                  • #71958
                    Jim Kosloskey
                    Participant

                      Mike,

                      Since this is a delimited file perhaps the source system has an option as to how to express negative numbers (many do) and could change their output to have a preceeding sign. Of course then you might have to deal with a leading +.

                      The use of parens to indicate a negative number is valid but not always useful.

                      email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 61 years IT – old fart.

                    • #71959
                      Mike Campbell
                      Participant

                        Jim,

                        I agree 1000%.  However, this particular vendor really doesn’t play nice with others, and is always looking to add $$$ to their tab.  

                        I was able to get the output as desired thanks to the good ideas. The concat expression worked as designed!  

                        Thanks again Sir!

                    Viewing 7 reply threads
                    • The forum ‘Cloverleaf’ is closed to new topics and replies.