# Formatting numbers in a Grid

I have a report that I currently export to Excel in order to format it nicely. I'd like to be able to produce a reasonably well formatted report directly in Mathematica. It looks like I can use Grid in order to set up the structure of the report. However I'd like to also format the numbers. I see that I can use NumberForm to handle some of the formatting, but I can't seem to then get the output from NumberForm to work inside Grid. Probably because NumberForm "prints" the results. Additionally I have some columns that appear in scientific notation if the number is large enough. I would like that column to have all in scientific notation or none in scientific notation. I tried using ExponentFunction in NumberForm, but without begin able to embed NumberForm results in Grid it didn't work. I was hoping that there might be some global setting for this threshold.

In addition to the above, I'd appreciate any suggestions about formatting a 2-dimensional table in Mathematica without having to go to Excel.

EDIT - sample:

I haven't gotten as far as headings. I'd want to align the columns. Colums 2 & 4 should probably stay in scientific notation for all numbers. columns 3 & 5 are probably best as integers - I can round them. A sample output, without formatting or headings is as follows.

Grid[Values[joinPMLs[group1CA, group2CA]] /. Missing["Unmatched"] -> "NA"]


• Please provide minimal sample data (array) and column/row headings that represent the range of issues to be addressed. Apr 12, 2017 at 19:50
• you need to appy NumberForm to individual entries, ie Grid[Map[NumberForm[#, 2] &, matrix, {2}]] , not Grid[NumberForm[matrix, 2]]] See also TableForm Apr 12, 2017 at 20:30

TableForm[
{#[[1]], EngineeringForm[#[[2]], {3, 1}]} & /@
Table[{RandomReal[], RandomReal[10^5]}, {10}],
TableHeadings -> {None, {"Normal", "Engineering Form"}}
]


If you have an association, you can do it right away, if you have a list of lists, you need to convert it into an association and then perform formatting on individual columns, similar to what you would do in Excel, after which you can use Grid or any other layout function:

data = {{1, 200000, 3, "string", Sin[z]/2},
{100, 200, 1.5, 300, Sum[1/Cos[x], {x, a, b}]}};

adata = Inner[Rule,Table["C" <> ToString@i, {i, Length[data[[1]]]}], Transpose[data], Association];


Then you can do something like this:

(Query[All, {
"C2" -> N /* (ScientificForm[#, 5] &),
"C3" -> Round,
"C4" -> (If[IntegerQ@#, IntegerName[#], #] &),