Re: Export table problem
- To: mathgroup at smc.vnet.net
- Subject: [mg30965] Re: [mg30891] Export table problem
- From: Dale Horton <daleh at wolfram.com>
- Date: Fri, 28 Sep 2001 03:55:18 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 01:16 AM 9/23/2001, maarten.vanderburgt at icos.be wrote:
>Hallo,
>
>Below I generate a table of numbers, which I round to get numbers with 2
>decimals precision. I want to export them in a ascii file. In my output
>file I get some numbers like 1.4000000000000001 instead of simply 1.4.
>Where does this extra 0.0000000000000001 come from? Is this a bug? How can
>I get rid of it without editing my file.?
>
>Thanks for your help
>
>Maarten van der Burgt
>Belgium
I'm not sure, but the extra digits come from the kernel, not the Export.
In[1]:= data=Round[100*Table[{i,i/5,i/3},{i,1,20}]]/100.;
In[2]:= data//InputForm
Out[2]//InputForm=
{{1., 0.2, 0.33}, {2., 0.4, 0.67}, {3., 0.6, 1.},
{4., 0.8, 1.33}, {5., 1., 1.67}, {6., 1.2, 2.},
{7., 1.4000000000000001, 2.33}, {8., 1.6, 2.67},
{9., 1.8, 3.}, {10., 2., 3.33}, {11., 2.2, 3.67},
{12., 2.4, 4.}, {13., 2.6, 4.33},
{14., 2.8000000000000003, 4.67}, {15., 3., 5.},
{16., 3.2, 5.33}, {17., 3.4, 5.67}, {18., 3.6, 6.},
{19., 3.8000000000000003, 6.33}, {20., 4., 6.67}}
You can always pre-process data to control the format of Table Export.
In[3]:= newdata=Map[ToString[NumberForm[#,2]]&, data,{2}];
In[4]:= Export["table.txt",newdata,"Table"];
In[5]:= !!table.txt
From In[5]:=
1. 0.2 0.33
2. 0.4 0.67
3. 0.6 1.
4. 0.8 1.3
5. 1. 1.7
6. 1.2 2.
7. 1.4 2.3
8. 1.6 2.7
9. 1.8 3.
10. 2. 3.3
11. 2.2 3.7
12. 2.4 4.
13. 2.6 4.3
14. 2.8 4.7
15. 3. 5.
16. 3.2 5.3
17. 3.4 5.7
18. 3.6 6.
19. 3.8 6.3
20. 4. 6.7
-Dale