egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[soved]formatting numbers

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
tueb
Halfop


Joined: 04 Oct 2007
Posts: 76
Location: #quiz.de @ irc.gamesurge.net

PostPosted: Wed Feb 18, 2009 5:48 am    Post subject: [soved]formatting numbers Reply with quote

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
View user's profile Send private message Visit poster's website
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Wed Feb 18, 2009 9:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
tueb
Halfop


Joined: 04 Oct 2007
Posts: 76
Location: #quiz.de @ irc.gamesurge.net

PostPosted: Thu Feb 19, 2009 5:25 am    Post subject: Reply with quote

it works,


thx
_________________
#Quiz.de @ irc.GameSurge.net
JavaChat
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber