3
$\begingroup$

I would like to print out an list of reals in a table with perfectly identical number of digits so that they can be perfectly right-aligned. However, once I convert them to strings, TableForm no longer prints them in a column:

  TableForm[RandomReal[1, 20], TableAlignments -> Right]
  TableForm[NumberForm[RandomReal[1, 20], {5, 3}], TableAlignments -> Right]

The first output has an inconsistent number of digits. The second is horizontal. Is there a good workaround for this issue?

$\endgroup$
1

1 Answer 1

4
$\begingroup$
NumberForm[#, {5, 3}] & /@ RandomReal[{0, 1}, 20] // TableForm
$\endgroup$
2
  • $\begingroup$ Can you explain structure of this? What kind of object does TableForm return and why does NumberForm apply to it? $\endgroup$
    – Wynne
    Commented Mar 20, 2018 at 15:56
  • $\begingroup$ ...// TableForm is equivalent to TableForm[...] $\endgroup$ Commented Mar 20, 2018 at 16:50

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.