V 12.1 on windows.
I do not remember if I've seen this and googling is not helping.
I wanted to format a numerical matrix for display using MatrixForm
. But first I wanted to apply NumberForm
on each entry, because I wanted all entries to have same width when displayed (so they do not shift around during display and running.
But NumberForm
does not work well with MatrixForm
. Is there a way around this?
a = {{1.3432, 34.432123}, {5.65454, 78.9883}}
MatrixForm[a]
And now
a = {{1.3432, 34.432123}, {5.65454, 78.9883}};
b = NumberForm[a, {2, 2}]
And it is the above I want to display in MatrixForm
But it does not work on it due to the NumberForm
wrapper in between
MatrixForm[b]
Also doing things in reverse ofcourse does not work either
NumberForm@MatrixForm[a]
I could ofcourse use Round
on the matrix first, then apply MatrixForm
but I prefer to use things like NumberForm
and AccountingForm
since they allow more control on the format.
Is there a better way to do the above?
Map[NumberForm[#, {2, 2}] &, {{1.3432, 34.432123}, {5.65454, 78.9883}}, {2}] // MatrixForm
$\endgroup$(a // MatrixForm) /. x_?NumberQ :> NumberForm[x, {2, 2}]
$\endgroup$