Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] Rounding clips

Expand Messages
  • Axel Berger
    ... Why? ^!Calc does correct rounding all on its own. Try the following after highlighting your number. N.B: It seems ^!Calc can t be nested, so I had to make
    Message 1 of 8 , Feb 4, 2011
    • 0 Attachment
      John Shotsky wrote:
      > Has anyone written any clips to perform rounding of numbers?

      Why? ^!Calc does correct rounding all on its own. Try the following
      after highlighting your number.
      N.B: It seems ^!Calc can't be nested, so I had to make it two lines.

      ^!InsertSelect ^$Calc(^$GetSelection$/100;0)$
      ^!InsertText ^$Calc(^$GetSelection$*100;0)$

      Axel
    • flo.gehrke
      ... John, Are you dealing with full text or a list of numbers? If it s full-text the following clip could possibly work... ^!SetHintInfo Working...
      Message 2 of 8 , Feb 5, 2011
      • 0 Attachment
        --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
        >
        > Here are a couple example numbers:
        > 19945
        > 19967
        >
        > The first result should be 19900 (...) The second result
        > should be 20000 (based on the 4th digit rounding up.)

        John,

        Are you dealing with full text or a list of numbers? If it's full-text the following clip could possibly work...

        ^!SetHintInfo Working...
        ^!SetScreenUpdate Off
        ^!Jump 1
        ^!Find "\b\d{5}\b" RS
        ^!IfError End
        ^!InsertSelect ^$Calc(^$Calc(^$GetSelection$/100;0)$*100)$
        ^!Goto Skip_-3

        If it's a list of numbers you could speed up the job with...

        ^!SetHintInfo Working...
        ^!SetScreenUpdate Off
        ; Copy selected numbers to the clipboard...
        ^!SetClipboard ^$GetDocListAll("\d{3}[0-4][0-9]";"$0\r\n")$
        ; ...and remove those numbers from the list
        ^!Replace "^\d{3}[0-4][0-9](\R|\Z)" >> "" WARS
        ; Round remaining numbers
        ^!Jump 1
        ^!Find "^\d{5}$" RS
        ^!IfError Out
        ^!InsertSelect ^$Calc(^$Calc(^$GetSelection$/100;0)$*100)$
        ^!Goto Skip_-3
        :Out
        ; Insert selected numbers from clipboard
        ^!InsertText ^P^$GetClipboard$
        ; Replace all the last two digits with '00'
        ^!Replace "^\d{3}\K\d{2}$" >> "00" WARS

        I've tested both clips with a list of 10,000 numbers. For me, the first clip needs 38 sec, the second clip needs 17 sec to do the job.

        Regards,
        Flo

        P.S. The ^$Calc$ is borrowed from Axel Berger showing how it can be nested ;-)
      • John Shotsky
        Thanks, Flo, that works great. And, I learned something again, as usual. :-) Regards, John Recipe formatting tools:
        Message 3 of 8 , Feb 5, 2011
        • 0 Attachment
          Thanks, Flo, that works great. And, I learned something again, as usual. :-)

          Regards,
          John
          Recipe formatting tools: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com
          RecipeTools FTP Site: <ftp://recipetoolsftp.gotdns.com/> ftp://recipetoolsftp.gotdns.com
          Beaverton Weather: <http://shotsky.gotdns.com/> http://shotsky.gotdns.com

          From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
          Sent: Saturday, February 05, 2011 10:02 AM
          To: ntb-clips@yahoogroups.com
          Subject: [Clip] Re: Rounding clips


          --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
          >
          > Here are a couple example numbers:
          > 19945
          > 19967
          >
          > The first result should be 19900 (...) The second result
          > should be 20000 (based on the 4th digit rounding up.)

          John,

          Are you dealing with full text or a list of numbers? If it's full-text the following clip could possibly work...

          ^!SetHintInfo Working...
          ^!SetScreenUpdate Off
          ^!Jump 1
          ^!Find "\b\d{5}\b" RS
          ^!IfError End
          ^!InsertSelect ^$Calc(^$Calc(^$GetSelection$/100;0)$*100)$
          ^!Goto Skip_-3

          If it's a list of numbers you could speed up the job with...

          ^!SetHintInfo Working...
          ^!SetScreenUpdate Off
          ; Copy selected numbers to the clipboard...
          ^!SetClipboard ^$GetDocListAll("\d{3}[0-4][0-9]";"$0\r\n")$
          ; ...and remove those numbers from the list
          ^!Replace "^\d{3}[0-4][0-9](\R|\Z)" >> "" WARS
          ; Round remaining numbers
          ^!Jump 1
          ^!Find "^\d{5}$" RS
          ^!IfError Out
          ^!InsertSelect ^$Calc(^$Calc(^$GetSelection$/100;0)$*100)$
          ^!Goto Skip_-3
          :Out
          ; Insert selected numbers from clipboard
          ^!InsertText ^P^$GetClipboard$
          ; Replace all the last two digits with '00'
          ^!Replace "^\d{3}\K\d{2}$" >> "00" WARS

          I've tested both clips with a list of 10,000 numbers. For me, the first clip needs 38 sec, the second clip needs 17 sec
          to do the job.

          Regards,
          Flo

          P.S. The ^$Calc$ is borrowed from Axel Berger showing how it can be nested ;-)



          [Non-text portions of this message have been removed]
        • flo.gehrke
          ... Thanks, John! I just found out that it s faster with ^!InsertText ^$Calc... -- there s no ^!InsertSelect ^$Calc... needed here. New runtime: 20 resp.
          Message 4 of 8 , Feb 5, 2011
          • 0 Attachment
            --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
            >
            > Thanks, Flo, that works great...

            Thanks, John!

            I just found out that it's faster with '^!InsertText ^$Calc...' -- there's no '^!InsertSelect ^$Calc...' needed here. New runtime: 20 resp. 11 sec with 10,000 lines.

            Flo
          • Axel Berger
            ... So nesting Calcs does work after. It does here too now, no idea what that error I caught last time was about. Axel
            Message 5 of 8 , Feb 5, 2011
            • 0 Attachment
              John Shotsky wrote:
              > ^!InsertSelect ^$Calc(^$Calc(^$GetSelection$/100;0)$*100)$

              So nesting Calcs does work after. It does here too now, no idea what
              that error I caught last time was about.

              Axel
            Your message has been successfully submitted and would be delivered to recipients shortly.