Created
August 12, 2008 22:02
-
-
Save Koitaro/5158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc addcomma {num} { | |
set s {}; set r {} | |
if {$num < 0} { | |
set result "-" | |
set num [expr abs($num)] | |
} | |
lassign [split $num .] upper lower | |
set len [string length $upper] | |
for {set i 0} {$i < $len} {incr i} { | |
set s [list [string index $upper $i] $s] | |
} | |
for {set i 1} {$i <= $len} {incr i} { | |
lassign $s top s | |
set r [list $top $r] | |
if { [llength $s] && ![expr {$i % 3}] } { set r [list "," $r] } | |
} | |
while {[llength $r]} { lassign $r top r; append result $top } | |
if {$lower ne {}} { append result "." $lower } | |
return $result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment