measurement conversion

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf measurement conversion

  • Creator
    Topic
  • #53220
    Gary Atkinson
    Participant

      Hi guys-

      Maybe my brain is not working right today, but here goes.  I am getting height and weight data with two different units of measure in a Z segment in which I need to format to one unit of measure.  Here is an example–>

      ZCR|||||||NY|||136^10.95|5^8.25

      136^10.95 == the weight

      5^8.25  == the height

      136 is in kilograms

      10.95 is in grams

      5 meters

      8.25 centimeters

      So…I need the total weight in kilograms and total height in centimeters.  Any ideas on how to do this in TCL?  ðŸ™‚

    Viewing 4 reply threads
    • Author
      Replies
      • #76961
        Charlie Bursell
        Participant

          If you divide grams by 1000 you get kilograms then just add together

          Likewise if you multiply meters by 100 you get centimeters, then just add

        • #76962
          Gary Atkinson
          Participant

            duh I was thinking it was more complicated than that 😳 Is there a tcl command to only allow two decimal points in a number?  Like 100.54545 turns into 100.54

          • #76963
            Charlie Bursell
            Participant

              You can play around with the global value tcl_precision.  It defaults to 12.  It will round so you may want to set it to 3.  Try this

              set sav $::tcl_precision   ;# Save current value

              set ::tcl_precision  3      ;# change precision

              expr 1.222222 + 3.333333

               => 4.56

              # Set it back

              set ::tcl_precision  $sav

              BTW:  :: means global.  or you could just define tcl_precision as global

            • #76964
              Chris Williams
              Participant

                Hey Gary,

                Is this typical data? If these numbers are metric you’ve got a patient who weighs around 300 lbs and is about 16 ft tall.  ðŸ˜€  Just guessing, but a patient who weighs 136 lbs and is 5 ft 8 in sounds more realistic.

                If you’re looking for a one-line precision solution you could take the result of your calculation and just format it with

                [format “%0.2f” $value]

                Cheers.

              • #76965
                Gary Atkinson
                Participant

                  LOL, those were numbers from a test case  ðŸ˜† Thanks for the tip on using format command.

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