Group Abstract Group Abstract

Message Boards Message Boards

0
|
10.2K 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
POSTED BY: Tomas Garza
Posted 9 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
POSTED BY: Sander Huisman
POSTED BY: Vladimir Ivanov
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