| View previous topic :: View next topic |
| Author |
Message |
tueb Halfop
Joined: 04 Oct 2007 Posts: 76 Location: #quiz.de @ irc.gamesurge.net
|
Posted: Wed Feb 18, 2009 5:48 am Post subject: [soved]formatting numbers |
|
|
Hi,
I'm looking for a away to format a number from 1234567890 to 1,234,567,890
I already tried [format "%5.3f" $number] and similar versions, but I cannot find the right way.
thanks for your help,
tueb _________________ #Quiz.de @ irc.GameSurge.net
JavaChat
Last edited by tueb on Thu Feb 19, 2009 5:26 am; edited 1 time in total |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
Posted: Wed Feb 18, 2009 9:53 pm Post subject: |
|
|
Check out the "commas" proc from http://wiki.tcl.tk/1591
| Quote: | %commas 123456789 ;# naturally, it defaults for use with large decimal integers
123,456,789 |
| Code: | proc {commas} {var {num 3} {char ","}} {
set len [string length $var]
set first [expr $len - $num]
set x ""
while { $len > 0} {
# grab left num chars
set lef [string range $var $first end]
if {[string length $x] > 0} {
set x "${lef}$char${x}"
} else {
set x ${lef}
}
# grab everything except left num chars
set var [string range $var 0 [expr $first -1]]
set len [string length $var]
set first [expr $len - $num]
}
return $x
} |
_________________ TCL the misunderstood |
|
| Back to top |
|
 |
tueb Halfop
Joined: 04 Oct 2007 Posts: 76 Location: #quiz.de @ irc.gamesurge.net
|
Posted: Thu Feb 19, 2009 5:25 am Post subject: |
|
|
it works,
thx _________________ #Quiz.de @ irc.GameSurge.net
JavaChat |
|
| Back to top |
|
 |
|