Takes a number and inserts a comma (or separator of your choice) between every third digit.
| 1 2 3 4 | proc comma {num {sep ,}} {
    while {[regsub {^([-+]?\d+)(\d\d\d)} $num "\\1$sep\\2" num]} {}
    return $num
}
 | 
Numbers displayed with the appropriate commas are much easier for a person to read. This code is based on an example from the Perl documentation.
    Tags: text
  
  

 Download
Download Copy to clipboard
Copy to clipboard
There's another recipe which does the same thing: http://code.activestate.com/recipes/146220-inserts-thousand-separators-into-a-number/ This recipe was submitted first, but the other one has comments, so I voted the other recipe up instead of this one.