# Unexpected behavior from NumberForm of a matix [duplicate]

If I calculate the dimension of the matrix after NumberForm directly, then there will be something wrong

test = NumberForm[IdentityMatrix[2], 2];
test // Dimensions
(*output {2}, but {2,2} is expected*)


If I show the result of NumberForm and then calculate the dimension, the result is right

{{"1","0"},{"0","1"}} //Dimensions
(*ouput {2,2}*)


What causes this? Is it a bug?

## marked as duplicate by m_goldberg, MarcoB, Feyre, happy fish, corey979Nov 24 '16 at 21:59

• Please do not add the bugs tag to your own questions. This is a special tag that is meant to be added by someone else than the original poster, after the bug has been verified by the community. – Szabolcs Nov 24 '16 at 12:13

This is not a bug:

Head[test]
(* NumberForm *)


Generally all *Form function, including NumberForm, MatrixForm, etc. are wrappers that are meant to display the expression only. In fact the output indicates the presence of the wrapper:

Once the expression is wrapped, it is not suitable for calculations. Or you need to extract it to do calculations.

MatrixQ[test]
(* False *)

MatrixQ[First[test]]
(* True *)

Dimensions[First[test]]
(* {2, 2} *)


• Thanks! Is there any function similar to NumberForm which does change the number to a string (not displays the expression only)? – Eden Harder Nov 24 '16 at 12:33
• @EdenHarder ToString. But you must apply it to numbers individually, not to a list of numbers. You can also use ToString@NumberForm[number]. – Szabolcs Nov 24 '16 at 12:42
• Isn't StandardForm an exception? – QuantumDot Nov 25 '16 at 1:52
• @QuantumDot No. The confusing bit is that SomeForm[x] then % gives x and not SomeForm[x]. Out treats these forms specially and doesn't record them. See \$OutputForms. – Szabolcs Nov 25 '16 at 7:47