4
$\begingroup$

Assume that the output of my calculation is a and is a number such as:

a = 100.1252135246354847;

N[a] gives me 100.125

However, when I try to save my data, a via export such as :

Export["/path/to/file/with/extension/dat", N[a]]

My eventual filename.dat has 100.12521352463548 and not 100.125. So is the precision of digits/most significant digits for display only?

I also tried NumberForm[a,6] and I get NumberForm[100.1252135246354847`18.000543455259304, 6] in my data file!

What am I doing wrong?

Edit (possible solution):

Replacing N[a] with SetPrecision[a,5] helped. I wasn't sure if I should have this in the ANSWER section because the solution may be quite trivial and may not warrant being in the answer section. Any thoughts on that (whether or not I should answer this question or let the solution remain as an appended "edit")

$\endgroup$
  • 1
    $\begingroup$ By the way, after you enter N[a], edit the output (or press Ctrl+Shift+L) to see the full machine form. $\endgroup$ – amr Sep 24 '12 at 17:12
2
$\begingroup$

Put the path between the quotation marks.

a = 100.1252135246354847;  
Export[StringJoin["", ToString[N[a, 6]], ".dat"], a]  

100.125.dat

|improve this answer|||||
$\endgroup$
4
$\begingroup$

Replacing N[a] with SetPrecision[a,5] helped. The above answer by Fred Daniel Kline helps too but isn't really what I am looking for.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.