# How to align TableForm entries at the decimal point and give it two-digit right-side floating point precision for monetary amounts?

My question essentially asks everything but I shall rephrase it to make certain it is well understood.

1. How to print all entries in rows of a column so that they align perfectly at the decimal point.

2. How to make 2-digit floating point precision for cents values (i.e. $1.98)? 3. If this cannot be done with TableForm can you suggest another option? Here is my Mathematica code... carValue := RecurrenceTable[{a[i] == a[i - 1] * 0.90, a[1] == 30000 , y[i] == i}, {y, a}, {i, 15}] TableForm[carValue , TableHeadings -> {None, {"Year", "Car Price"}}] Labeled[Select[carValue, #[[2]] < 8000 &, 1][[1, 1]], "Year when valued less than$8000:", Left]


carValue :=
RecurrenceTable[{
a[i] == a[i - 1]*0.7
, a[1] == 30000
, y[i] == i}
, {y,a}, {i, 15}]

Grid[
Join[
{{"Year", Item["Car Price", Alignment -> Right]}}
,Round[carValue, 0.01]
]
, Alignment -> "."
, Dividers -> {None, {False,True, False}}]


Notes :

TableForm has probably no way to align on the decimal point.

With Tableform, a workaround could be to use NumberForm[#, {10,2}] & to have equally formatted numbers, but it gives :

I don't like the 00 after the decimal point. Furthermore it' s not in the philosophy of your question.

That's the reason why I have used Grid.

But Grid doesnt' have the option TableHeading

This is not a problem, it suffices to add a row with the information. (Grid is very robust. It accepts rows of different length, which is very usefull)

Round is used to have only to 2 digits after the decimal point.

• thank you so much. your grid solution works just fine. May 1, 2020 at 12:08

Another option might be

carValue = RecurrenceTable[{a[i] == a[i - 1]*0.90, a[1] == 30000, y[i] == i}, {y, a}, {i, 15}];

carValueFixed = {First[#],
PaddedForm[Last[#], {7, 2}, DigitBlock -> 3,
NumberSeparator -> ",", NumberPadding -> {" ", "0"}]} & /@ carValue;

TableForm[carValueFixed, TableHeadings -> {None, {"Year", "Car Price"}}]


• thank you. another fine solution. May 1, 2020 at 23:25