# Mathematica Precision

How can I set the output precision of the following statement to 10 decimal places? I was looking through the documentation, and for some reason, all I could find was Accuracy[] or Precision[].

f[x_] := E^Cos[x]
NIntegrate[f[x], {x, 0, 2*Pi}]


Which, by default, evaluates to:

7.95493


Thank you for your time.

• This is all in the documentation: N, guides to numerical precision, presentation of numbers using NumberForm. Please at least make some effort with the documentation. Mar 28, 2012 at 3:56
• @Verbeia I was looking through the documentation, and for some reason, all I could find was Accuracy[] or Precision[] but nothing like what Artes mentioned. Mar 28, 2012 at 3:58
• It is helpful to mention this in your question, so we know what you've tried. Anyway, the documentation for Precision links to the tutorial I mentioned and to the guide page that mentions PrecisionGoal and AccuracyGoal. It was all one click away. Mar 28, 2012 at 4:04
• Thank you Verbeia. I will keep this in mind! Mar 28, 2012 at 4:06
• It's notable that the documentation for Precision links only indirectly through the tutorials to NumberForm. The direct links are only Accuracy, RealExponent, N, Chop, SetPrecision, MachineNumberQ, MachinePrecision, PrecisionGoal, WorkingPrecision, ExactNumberQ, NumberMarks. IMO, it'a a lot to go trawling through when looking for this answer. Mar 31, 2012 at 0:07

## 4 Answers

NIntegrate[f[x], {x, 0, 2*Pi}, WorkingPrecision -> 15, PrecisionGoal -> 10]

 7.95492652101285

• Oh yeah! Just what I needed. Thank you, Artes! Mar 28, 2012 at 3:56

The number of digits displayed for machine reals can also be controlled via a setting in the preferences dialog. Under Appearance > Formatting > Numbers, change the value for Number of digits displayed in output:

In[4]:= f[x_] := E^Cos[x]
In[5]:= NIntegrate[f[x], {x, 0, 2*Pi}]

Out[5]= 7.954926521


Note that this doesn't affect arbitrary-precision numbers, which show the digits appropriate for their precisions (shown in these examples after the backticks):

In[6]:= 1.234567894

Out[6]= 1.235

In[7]:= 1.2345678914

Out[7]= 1.2345678900000

• This has a downside of cluttering your notebook. The solution of @Vitaliy Kaurov is better in this respect. It only produces the long form numbers, when required. May 31, 2018 at 11:51

If you just want "10 decimal places" - you already have them and more. Mathematica just displays shorter version. You get your answer on default with 16 significant digits, - use NumberForm to see it:

f[x_] := E^Cos[x]
NumberForm[NIntegrate[f[x], {x, 0, 2*Pi}], 100]

 7.954926521012846


I intentionally exaggerated with 100 digit precision so you can see where the default digits are cut off. Also if SHIFT+ENTER (evaluate) your answer/number (output cell), you will see it again - your 16 digits appear in the input and shorten in the output:

In[1]:= 7.954926521012846

Out[1]= 7.95493


Use in the following way also.

 SetPrecision[NIntegrate[f[x], {x, 0, 2*Pi}], 15]
`