Incompatibility of Append and NumberForm? [closed]

Consider the code

list = {.12, .23, .34};
Append[Round[list, .1], 10]
Append[NumberForm[list, 1], 10]

The use of Round returns the expected result {0.1, 0.2, 0.3, 10}, whereas using NumberForm results in the error NumberForm::argct: NumberForm called with 3 arguments.”. Am I missing something? Mathematica version is 10.0.2.0.

=================

=================

1 Answer
1

=================

Please, just replace the built-in Append with some undefined append that does nothing and use InputForm to see what really happens

list = {.12, .23, .34};
append[NumberForm[list, 1], 10] // InputForm
(* append[NumberForm[{0.12, 0.23, 0.34}, 1], 10] *)

Now you see, that NumberForm is still wrapped around the list and you would append your 10 as 3rd argument which makes absolutely no sense.

In general you should only use things like NumberForm when you want to display something, because even when you use the syntax correctly

l2 = Append[NumberForm[#,1]&/@list,10]
(* {0.1,0.2,0.3,10} *)

is the resulting list really what you want? Look at the complete expression

InputForm[l2]
(* {NumberForm[0.12, 1], NumberForm[0.23, 1], NumberForm[0.34, 1], 10} *)

And now assume you want to get the Min from this list

Min[l2]
(* Min[10,0.1,0.2,0.3] *)

Doesn’t work, because the numbers only look like numbers.

  

 

The horror of NumberForm[0.12, 1] // ToBoxes confirms this beyond doubt.
– Martin John Hadley
Apr 29 ’15 at 13:26