Message Boards Message Boards

0
|
9134 Views
|
8 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Get number of digits to the right of the decimal point?

It may be a stupid question, but I cannot find an answer for a long time.

Let us calculate

In[1]:= x = 1/7.0

Out[1]= 0.142857

x has precision not less than 15:

In[2]:= Precision[x]

Out[2]= MachinePrecision

In[3]:= $MachinePrecision

Out[3]= 15.9546

But I can see only 5 digits after the point. The second argument of N does not help:

In[4]:= N[x, 15]

Out[4]= 0.142857

How can I see more digits of x?

Why I see a different result if I set the precision explicitely?

In[5]:= y = 1/7.0`15

Out[5]= 0.142857142857143
POSTED BY: Vladimir Ivanov
8 Replies

Yes, NumberForm[x,16] seems to be that I looked for. Thank you.

POSTED BY: Vladimir Ivanov

Sorry, the last post was sent by me (Tomas Garza)

POSTED BY: Tomas Garza
Posted 8 years ago

I go back to your original question: "How can I see more digits of x?"

So, the issue is not concerned with the actual number x, but rather with the value displayed (i.e., what you see) which by default is 6. The question, I insist, is not about precision, but about the number of digits displayed. I think (in my humble opinion) that you shouldn't bother about precision, which is an altogether different thing. If your number is exact (such as 1/7) then you can use N[1/7, n] to display n digits. Otherwise, why not use NumberForm? (check the online Help)

NumberForm[1/7., {16, 16}]

0.1428571428571428

POSTED BY: Updating Name

In fact,

x // InputForm

will give me all digits too. But all this ways are rather ugly, and I look for something more elegant. The best way I know now is to use

SetPrecision[x, n]
POSTED BY: Vladimir Ivanov

Thanks for your answers.

Concerning the first method: is there any way to see the digits I need without changing the global preferences? I mean that in one line of the notebook I may need 6 digits after the point, and in another one - 12.

Concerning the second method: I cannot catch the logic. Let us define two variables:

In[1]:= x = 1/7.0
Out[1]= 0.142857

In[3]:= Precision[x] // N
Out[3]= 15.9546

In[7]:= y = N[1/7, $MachinePrecision]
Out[7]= 0.1428571428571429

In[8]:= Precision[y] // N
Out[8]= 15.9546

One can see that x and y have the same value and same precision. However, from the viewpoint of Mathematica they are different. How it makes the difference?

It seems to me that in older than 6 versions of Mathematica there was no such problem. I was able to write something like

In[1]:= x = 1/7.0
Out[1]= 0.142857

In[2]:= N[x, 15]
Out[2]= 0.1428571428571429
POSTED BY: Vladimir Ivanov
RealDigits

gives you all the digits. Also, if you copy a number from the notebook (which looks like it has 6 digits) and paste it elsewhere, you will see all of them.

POSTED BY: Sander Huisman

Alternatively, you may use N directly with the rational 1/7 instead of converting it to Real with the decimal point:

In[4]:= N[1/7, 15]

Out[4]= 0.142857142857143

In[5]:= N[1/7, 25]

Out[5]= 0.1428571428571428571428571

POSTED BY: Tomas Garza

By default, only 6 digits are printed for machine precision numbers.

enter image description here

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

Group Abstract Group Abstract