|
Description:
Takes a number and inserts a comma (or separator of your choice) between
every third digit.
Source: Text Source
proc comma {num {sep ,}} {
while {[regsub {^([-+]?\d+)(\d\d\d)} $num "\\1$sep\\2" num]} {}
return $num
}
The license for this recipe is available here.
Discussion:
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.
|