Why the following code

Table[ N[i, 4], {i, 1, 2, 0.5}]

do not output numbers with fixed number of digits, but gives this {1., 1.5, 2.}

while there is no problems with this code

Table[ N[i, 4], {i, 1, 2}]

the output as expected is {1.000, 2.000}

  • 3
    $\begingroup$ As @eyorble has pointed out, the presision of 0.5 is machine-precision. You could controll this by doing Table[ N[i, 4], {i, 1, 2, SetPrecision[ 0.5, 4 ] } ] where you specify the precision to be used for 0.5. $\endgroup$
    – gwr
    Commented Dec 30, 2017 at 16:51
  • 1
    $\begingroup$ ....or {i, 1, 2, 1/2} $\endgroup$ Commented Dec 30, 2017 at 16:57
  • $\begingroup$ Helpful in this regard: How to Control the Precision and Accuracy of Numerical Results. $\endgroup$
    – gwr
    Commented Dec 30, 2017 at 17:02

1 Answer 1


The presence of 0.5 in the iterator makes Table use machine-precision numbers for i, which apparently N will not modify the precision on (even if the requested precision is less than MachinePrecision).

To generate the list with the precision you want:

Table[ N[i,4], {i, 1,2, 1/2}]
  • $\begingroup$ Is there a way to tell Mathematica to consider a decimal as arbitrary precision? $\endgroup$
    – MTCoster
    Commented Dec 30, 2017 at 17:39
  • 3
    $\begingroup$ Rationalize[x,0] will return the closest rational number Mathematica can find, which will be arbitrary precision and usually fairly close (it's impossible to rationalize irrational or transcendental numbers, after all). However, it's not possible to directly say that some decimal number is infinitely precise. If you merely want an arbitrary finite precision, copy and paste any non-machine precision number and note the backtick followed by a number -- that's the listed precision of the number. $\endgroup$
    – eyorble
    Commented Dec 30, 2017 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.