Group Abstract Group Abstract

Message Boards Message Boards

0
|
289 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Display 16 digits after the decimal place?

Hello Community,

How can I force Mathematica to display 16 digits after the decimal place ?
Instead of the 6 digits by default.
I have tried what you can see below and got nothing I wanted.
Moreover where/how to do that for every session of Mathematica ?
In the options Inspector?
Thank you for your help...I am a bit lost.
King regards to all,
Jean-Michel

In[7]:= Sin[-1.002547]

Out[7]= -0.842844

In[3]:= N[Sin[-1.002547], 16]

Out[3]= -0.842844

In[6]:= $MaxPrecision := 16

In[8]:= Cos[1.25]

Out[8]= 0.315322

In[13]:= Block[{$MaxExtraPrecision = 16}, N[Cos[1.205], 16]]

Out[13]= 0.357693
Attachments:
5 Replies
Posted 8 days ago

There is an option, PrintPrecision, that sets how many significant digits are shown in notebook output. Default 6. To change it globally one can use Preferences from the Edit menu:

enter image description here

Or in Option Inspector:

enter image description here

The option can also be set for individual instances of functions such as InputField:

InputField[0.123456789, BaseStyle -> {PrintPrecision -> 10}]
POSTED BY: Hans Milton
Posted 9 days ago

Unless otherwise indicated, when you create a number with a decimal point it will have machine precision (about 16 decimal digits). Since 16 digits is what you want, all you need to do is ask to see all significant digits. The front end typically shows only a few significant digits for machine precision number, but it "knows" all of them.

Sin[-1.002547] // FullForm
(* -0.8428444038954503` *)

So, any subsequent calculation with that value would use all the digits (i.e. many more than you see displayed). However, any subsequent arithmetic can only preserve or lose precision, it can't gain precision. So, if you need even more digits, you'll need to tell Mathematica to start with higher precision. Let's say you wanted that number to have 50 digits of precision. Then you could do this:

Sin[-1.002547`50]
(* -0.84284440389545029858668699605171893416627484058817 *)

Alternatively,

Sin[SetPrecision[-1.002547, 50]]
(* -0.84284440389545034001414581446602226926579398448717 *)

Side note, the function N doesn't automatically add precision. It will try to give a result to the requested precision, but precision can't be gained, so if you start with machine precision, that's the max you can end up with.

N[Sin[-1.002547], 50] // FullForm
(* -0.8428444038954503` *)

I should add that precision is ultimately relative to the binary representation and only significant digits are counted. So when you say you want to "force Mathematica to display 16 digits after the decimal place" the above techniques might actually not always work if you literally need "16 digits after the decimal place". To control exactly how a number is displayed, you would need to use NumberForm or one of the related *Form functions.

POSTED BY: Eric Rimbey

From the documentation on N[expr]:

Unless numbers in expr are exact, or of sufficiently high precision, N[expr,n] may not be able to give results with n-digit precision.

So - instead of writing Sin[1.002547] an exact argument should be given:

N[Sin[1002547/1000000],50]
(*  Out:    0.84284440389545029858668699605171893416627484058817  *)
POSTED BY: Henrik Schachner

Hans : I am so grateful to you. This does solve this issue I've been fighting for months... Best regards,

Jean-Michel

Thank you very much Hans and the two others who replied kindly to my question. Hans : It is exactly what I was looking for. Have a great day and kind regards,

Jean-Michel

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard