4
$\begingroup$

Let's try to typeset a couple of numbers with a precision accuracy of 4:

0``4
1``4
1000000``4

enter image description here

I do not want the numbers returned with *10^... therefore I use NumberForm with ExponentFunction set to Null:

NumberForm[0``4, ExponentFunction -> (Null &)]
NumberForm[1``4, ExponentFunction -> (Null &)]
NumberForm[1000000``4, ExponentFunction -> (Null &)]

enter image description here

However as you can see, the 0 is still in exponent form...! It should be 0.000 much like the 1.000.

A bug?

Any ideas on how to circumvent this behaviour?

$\endgroup$
  • $\begingroup$ I wonder if this hasn't been discussed before. I'll see what I can find. Thanks for pointing out this issue. $\endgroup$ – Mr.Wizard Dec 9 '16 at 12:27
3
$\begingroup$

On a circumvent side, since ExponentFunctiondoes return an exponent for 0 even after we asked not to do so, we can use the NumberFormat function to typeset it manually:

NumberForm[0``4,
 NumberFormat -> (If[#3 =!= "", StringJoin[{#1, Table["0", Abs@ToExpression@#3 - 1]}], #1] &),
 ExponentFunction -> (Null &)]

(* 0.000 *)

Note, this will work when you want Accuracy as shown in OP question (``), not Precision (`).

$\endgroup$
  • $\begingroup$ Thankfully I did indeed mean accuracy and not precision, your workaround works thanks! An odd edge case for NumberForm. $\endgroup$ – Quantum_Oli Dec 9 '16 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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