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

Any programs to format numbers out there?

Expand Messages
  • Mun Johl
    Hi, When in vim, I often want to format numbers. For example, when editing a Verilog file, I want to quickly change 12345678 to 12_345_678 for readability;
    Message 1 of 4 , Jun 30, 2006
      Hi,

      When in vim, I often want to format numbers. For example, when editing
      a Verilog file, I want to quickly change 12345678 to 12_345_678 for
      readability; and when editing an email, sometimes I'd like to change
      12345678 to 12,345,678 .

      I did a search for programs to format numbers, but didn't really find
      anything suitable. Before I take on the task myself, I thought I'd ask
      if anyone knows of any such program/script/plugin.

      Thanks in advance.

      Regards,

      --
      Mun
    • Jean-Pierre Radley
      ... I have some accounting programs with give me large dollar¢s amounts; I use sed to prettify them by adding commas. Play with this: echo
      Message 2 of 4 , Jun 30, 2006
        Mun Johl typed (on Fri, Jun 30, 2006 at 03:43:34PM -0700):
        | Hi,
        |
        | When in vim, I often want to format numbers. For example, when editing
        | a Verilog file, I want to quickly change 12345678 to 12_345_678 for
        | readability; and when editing an email, sometimes I'd like to change
        | 12345678 to 12,345,678 .
        |
        | I did a search for programs to format numbers, but didn't really find
        | anything suitable. Before I take on the task myself, I thought I'd ask
        | if anyone knows of any such program/script/plugin.

        I have some accounting programs with give me large dollar¢s amounts;
        I use sed to prettify them by adding commas.

        Play with this:

        echo ' 123456789876543.21' |
        sed '
        : C
        /[0-9][0-9][0-9][0-9][,.]/s/ \([-+0-9]*[0-9]\)\([0-9][0-9][0-9][,.]\)/\1,\2/g
        t C
        '

        --
        JP
        ==> http://www.frappr.com/cusm <==
      • Trent Gamblin
        ... To add commas to all large numbers. Replace the comma with an underscore to add underscores instead.
        Message 3 of 4 , Jun 30, 2006
          On Fri, 2006-06-30 at 15:43 -0700, Mun Johl wrote:
          > Hi,
          >
          > When in vim, I often want to format numbers. For example, when editing
          > a Verilog file, I want to quickly change 12345678 to 12_345_678 for
          > readability; and when editing an email, sometimes I'd like to change
          > 12345678 to 12,345,678 .
          >
          > I did a search for programs to format numbers, but didn't really find
          > anything suitable. Before I take on the task myself, I thought I'd ask
          > if anyone knows of any such program/script/plugin.
          >
          > Thanks in advance.
          >
          > Regards,

          You can use the regular expression:
          :%s/\(\d\)\(\(\d\d\d\)\+\d\@!\)\@=/\1,/g
          To add commas to all large numbers. Replace the comma with an underscore
          to add underscores instead.
        • Mun Johl
          Hi, Thanks for the suggestions! I have working maps :) -- Mun
          Message 4 of 4 , Jul 2, 2006
            Hi,

            Thanks for the suggestions! I have working maps :)

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