A single format command will provide the desired output:
format “%07.3f” 1.23
The 0 specifies leading zeros
The 7 specifies the TOTAL output field width including the decimal point (NOT just the number of digits to the left of the decimal)
The .3 specifies the number of places to the right of the decimal
The f specifies that this is a floating point number
Cheers.
That does appear to work perfectly. Thanks, Chris!
lappend input “12”
lappend input “12.15”
lappend input “1.23”
#xxx.xxx
foreach var $input {
set output [format “%07.3f” $var]
#set output [format “%0.3f” $var]
#set output [format “%07s” $output]
puts “$var: $output”
#Result:
#12: 012.000
#12.15: 012.150
#1.23: 001.230
}