TCL/TK Convert string to floating point and formatting the text
<p>I'm in trouble with this trivial problem. I need to read a text file with 2 column of values and write them in an output text file inside a table of 6 columns made by 8 spaces each one.</p>

<p>This is the input:</p>

<pre><code>30.1843 0.167333
33.5259 0.140436
37.0905 0.2e-3
39.4298 0.0973432
</code></pre>

<p>This is what I want in the output (two possible solution: or trim the number after the 8th values, or just write them in the scientific format)</p>

<pre><code>30.1843 0.16733  33.5259 0.14043  37.0905 0.11416
39.4298 0.09734
</code></pre>

<p>The focus of my script is:</p>

<pre><code>set FileInput [open $filename r]

set Row 0
while {[gets $FileInput line] &gt;= 0} { 
incr Row
                }
close $FileInput

set FileInput2     [open "Output-Table.txt"]
set Counter 0

while {$Counter &lt;= [expr ($Row/3)]} { 

gets $FileInput2 NodeList
gets $FileInput2 NodeList2
gets $FileInput2 NodeList3

puts $Output2 "[ format "%-7s" [lindex $NodeList {0}]] [ format "%-7s" [lindex $NodeList {1}]] [ format "-7s" [lindex $NodeList2 {0}]] [format "-7s" [lindex $NodeList2 {1}]] [ format "-7s" [lindex $NodeList3 {0}]] [ format "-7s" set Sesto [lindex $NodeList3 {1}]]"

incr Counter
}
</code></pre>

<p>The first problem is that I want to use </p>

<pre><code> format "-7e"
</code></pre>

<p>to write numbers in a scientific format, but it makes an error.</p>

<p>Secondly I would like to understand why the [format "-7s"] does not work in my script. The output table, is exactly the same of the input; instead, I want to obtain at maximum 8 digits for each column. </p>