Using field-formatters to format results of Org table formulae.
If you have a simple Org table like:
| 0.5 | | 1.5 | |-----| | |
And you want the A3 cell to contain the sum of A1 and A2 cells, you would add this at the bottom on that table and evaluate it (C-c C-c).
That formula reads as: “Set the value of the cell is last row
@>)1, first column (
$1) be equal to the sum of all cells in
the same column from row 1 (
@1) to second-to-the-last row (
But then you end up with an odd-looking
2. instead of
2.0 in the
| 0.5 | | 1.5 | |-----| | 2. | #+tblfm: @>$1=vsum(@1..@>>)
So I had posted a question on the Org mailing list to understand if this was a bug — it was not.
%0.1f formatter #
Thanks to the reply from Thierry Banel to that question, one of the
solutions is to use field formatters, like in
printf in C (and
many other languages):
| 0.5 | | 1.5 | |-----| | 2.0 | #+tblfm: @>$1=vsum(@1..@>>);%0.1f
f1 formatter #
Another solution, also from Thierry, was to use the Calc
formatter instead of
%0.1f (and similarly
f5 instead of
| 0.5 | | 1.5 | |-----| | 2.0 | #+tblfm: @>$1=vsum(@1..@>>);f1
- While the
%.1fformat is handy for those who are used to
printf()syntax, note that Calc unlimited precision numbers are converted to double floats before applying
f1operates on Calc numbers without conversion.