tcl to remove a decimal

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library tcl to remove a decimal

  • Creator
    Topic
  • #50453
    Hope Malin
    Participant

    I am just newly certified in Cloverleaf Level 1 and have had little, if any, exposure to tcl. I could use the help of some experts.

    We are currently running version Cloverleaf 5.3. I am working on an Xlate for a charge interface where the input is HL7 and the output is FRL. Most of the time, there will be no amount sent and in these cases, the receiving system wants 10 zeros. However, there will be occasions when an amount is sent,  and in those cases the receiving system will want the numeric characters but with no decimal point.

    Does anyone have any code that can be used to strip a decimal point but leave all of the digits in tact? Thanks!

Viewing 2 reply threads
  • Author
    Replies
    • #66137
      John Mercogliano
      Participant

      I had to do something similar.   Here is the xlate I wrote.  It takes in the value and the length you want returned padded with zero’s.  If there is no cents it will add two zero’s at the end.  Being this is an FRL you are sending to this is probably what you want also.  I am sending charges to HBOC/Medipac.

      Code:


      proc shs_xltFormatCurrency {} {
         upvar xlateId       xlateId
       xlateInList   xlateInList
       xlateInTypes  xlateInTypes
       xlateInVals   xlateInVals
       xlateOutList  xlateOutList
       xlateOutTypes xlateOutTypes
       xlateOutVals  xlateOutVals

      lassign $xlateInVals strCurrencyValue intLength

      set lstCurrencyValue [split $strCurrencyValue .]
      if { [llength $lstCurrencyValue] == 1 } {
      set strDollar $strCurrencyValue
      set strCents “00”
      } else {
      set strDollar [lindex $lstCurrencyValue 0]
      set strCents [lindex $lstCurrencyValue 1]
      }
      set xlateOutVals [list [format %0*s%-02s [expr $intLength – 2] $strDollar $strCents]]
      }

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

    • #66138
      Chris Williams
      Participant

      Or you might try:

      Code:

       set output [string map {. {}} [format “%011.2f” $input]]

      This formats the input value as 11 leading-zero characters with 2 of them to the right of the decmal, then string map removes the decimal to get you back to just the 10 digits. If the input value doesn’t contain a decimal point it considers the input to be whole dollars, otherwise it considers the number to be dollars and cents.

    • #66139
      John Mercogliano
      Participant

      Ohhhh.  That cut’s out about 8 lines of code 😯 Nice one liner Chris.

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

Viewing 2 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,115
Forums
28
Topics
9,290
Replies
34,422
Topic Tags
286
Empty Topic Tags
10