Field Formatters in Org table
— Kaushal ModiUsing 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).
#+tblfm: @>$1=vsum(@1..@>>)
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
result cell:
| 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.
Using printf
style %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
Using Calc f1
formatter #
Another solution, also from Thierry, was to use the Calc f1
formatter instead of %0.1f
(and similarly f5
instead of %0.5f
).
| 0.5 |
| 1.5 |
|-----|
| 2.0 |
#+tblfm: @>$1=vsum(@1..@>>);f1
- Note
- While the
%.1f
format is handy for those who are used toprintf()
syntax, note that Calc unlimited precision numbers are converted to double floats before applying%.1f
. Whereasf1
operates on Calc numbers without conversion.
See (org) References for more information on those field references. ↩︎