This piece of code inserts a thousandth separator into a decimal number, i.e. every 3 digits the separator character is inserted. courtesy Jeff Hobbs's bag of utilities.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # commify --
# puts commas into a decimal number
# Arguments:
# num number in acceptable decimal format
# sep separator char (defaults to English format ",")
# Returns:
# number with commas in the appropriate place
#
proc commify {num {sep ,}} {
while {[regsub {^([-+]?\d+)(\d\d\d)} $num "\\1$sep\\2" num]} {}
return $num
}
|