# Unexpected behavior from Accuracy

This is my code

Table[With[{x = 10^n + 1/17}, N[x, {Infinity, 5}]], {n, 0, 5}] // Column Or like this

SetAccuracy[Table[With[{x = 10^n + 1/17}, N[x]], {n, 0, 5}], 5] // Column Actually I just want 5-digit accuracy (effective number of digits to the right of the decimal point) and any precision. But the accuracy is 4 and sometimes it is 5.

### Update

The documentation has this usage as above So is it a bug in function of N?

• the issue is that N takes its accuracy/precision arguments in base 10, but actually constructs a binary result that best captures your specification. Note words like attempts and at most in the documentaiton for N – george2079 Dec 31 '15 at 16:36
• I'd say not a bug in N but a rather glaring omission in the docs to give that example and fail to point out that the accuracy does not always guarantee an exact number of decimal digits ultimately get displayed. – george2079 Dec 31 '15 at 16:44
• @george2079 Oh,Thinks a lot.Blame I was too careless and I have seen it in Detail . – yode Dec 31 '15 at 17:11
• @george2079 You should really make your comment an answer. – xzczd Jan 1 '16 at 4:40
• Well, actually I think there's a more general issue behind this and many other precision-related question in this site, that is, the rule for precision (not sure I've used the correct terminology) of Mathematica is just similar but not the same as that we used when we calculates with pencil and paper. Maybe we need a community wiki or something for this. – xzczd Jan 1 '16 at 4:56

You are misinterpreting the documentation. A number with no digits to the right of decimal place is considered to have 1 digit of accuracy. Consider

Grid[
With[{r = Range[0, 4]},
Prepend[
Table[With[{x = 10^n + 1/17}, N[x, {∞, a}]], {n, r}, {a, r + 1}],
r + 1]],
Alignment -> "Decimal",
Background -> {None, {GrayLevel[0.7], {White}}},
Dividers -> {Black, {2 -> Black}},
Frame -> True,
Spacings -> {2, {2, {0.7}}}] ### Edit

The number of digits seen in the table depends on 1) the setting for number–of-digits-displayed in Preferences and 2) the precision of the numbers being displayed. The accuracy setting does not factor into it.

The numbers that appear to have too many digits simply have higher precision than the others.

• Sorry for my poor expression.Such as N[Pi^10, {Infinity, 5}] give 4 digit but N[Pi^10, {Infinity, 6}] will give 6 digit after the decimal point,which is confuse me – yode Dec 31 '15 at 16:14
• As your table,The bottom line of the last two columns has a unexpected number of digits. – yode Dec 31 '15 at 16:19
• I like your answer +1, would be nice to have your comments on Help/Details, 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.  – user9660 Dec 31 '15 at 16:47
• I think this just re-illustrates the question.. – george2079 Dec 31 '15 at 16:51
 Table[N[10^n + 1/17, n + 6], {n, 0, 5}] // Column Or

 Table[NumberForm[10^n + 1/17., {12, 5}], {n, 0, 5}] // Column Or

Table[PaddedForm[10^n + 1/17., {12, 5}], {n, 0, 5}] // Column SetAccuracy only gives the desired result if you combine it with one of the number display functions:

p = 5;
AccountingForm[Column@Table[SetAccuracy[10^n + 1/17, p + 1], {n, 0, 15}], {Infinity,p}] • Actually I know there is a workaround to solve this problem.But what a mistake in my usage?If not,do you think a flaw is in function of N? – yode Dec 31 '15 at 13:34
• It's certainly not a flaw with N, but I agree that the behaviour of SetAccuracy is a little bit strange in this case. – eldo Dec 31 '15 at 14:03
• Have you seen the picture I update just now? – yode Dec 31 '15 at 14:06
• Have you seen the first part of my answer? N behaving exactly as you want. The picture you show just clarifies the fact that N[4, {Infinity, 2}] displays one digit after the decimal point and not two. – eldo Dec 31 '15 at 14:26
• N[Pi^10, {Infinity, 5}] give 4 digit but N[Pi^10, {Infinity, 6}] give 6 digit after the decimal point. – yode Dec 31 '15 at 14:58