I have a two-part question regarding NumberForm
First question
In my attempt at answering this i stumbled upon a strange behavior by NumberForm when the final result is exported.
Lets say I have a simple Table output as shown below which uses the command NumberForm
t1 = Table[{i, NumberForm[Range[i], {2, 2}]}, {i, 1, 2}]
Now if I export this it works fine
Export["try.dat", t1];
FilePrint["try.dat"]
(* 1 {1.00} *)
(* 2 {1.00, 2.00}*)
But if i slightly tweak the Table like this
t2 = Table[{i, NumberForm[Range[i + #], {2, 2}] & /@ Range[2]}, {i, 1, 2}]
Now on export NumberForm remains unevaluated
Export["try.dat", t2];
FilePrint["try.dat"]
(* 1 {NumberForm[{1, 2}, {2, 2}], NumberForm[{1, 2, 3}, {2, 2}]} *)
(* 2 {NumberForm[{1, 2, 3}, {2, 2}], NumberForm[{1, 2, 3, 4}, {2, 2}]} *)
So why is this happening?
Second question
Also while searching I found this where the OP asked and answered his own question regarding NumberForm but when I run his/her solution it's not giving the expected answer in my machine (Windows 8 with mma 9). Below is the code which the OP gave.
time = Table[i, {i, 0, 0.4, 0.01}];
time2 = Table[NumberForm[i, 6], {i, 0, 0.4, 0.01}];
op = Table[time[[i]]^2 + time[[i]], {i, 1, Length@time}];
Export["data.dat", Transpose@{time2, op}, "Table"];
FilePrint["data.dat"];
Can someone confirm what they get on running the above piece matches with whats given in that thread. I'm getting some numbers which are not formatted.
Export
. ift2
evaluated correctly, the export would have been fine. Andt2
does evaluate correctly on my system, which is V10 on OS X. $\endgroup$Export["data.dat", Transpose@{time2, NumberForm[#, 6] & /@ op}, "Table"];
you get the same result as in the linked answer. $\endgroup$