Re: Re: Anyone got a zero fill (left) tcl proc or fragment?

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Anyone got a zero fill (left) tcl proc or fragment? Re: Re: Anyone got a zero fill (left) tcl proc or fragment?

#56743
Tom Henderson
Participant

Just one word of caution about the format statement.  It sees numbers that start with a zero as octal numbers, so if you’re asking it to say, turn 0134 into 000134 it will bomb.  The solution is simple, though:  Just wrap the value with a [string trimleft 0] to first trim all the leading 0’s, if any, before formatting the number with the right number of leading zero’s.

For example:

set xlateOutVals [format “%06s” [string trimleft $xlateInVals 0]]

If you’re sure the values will never have a leading zero, then it’s not necessary.  But if they ever might….

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,435
Topic Tags
286
Empty Topic Tags
10