emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Org table: emphasizing calculated cell


From: Norwid Behrnd
Subject: Re: Org table: emphasizing calculated cell
Date: Fri, 27 Aug 2021 08:12:26 +0000

Dear Jarmo,

your observation is new to me because I only used the approach

```
#+TBLFM:  @4$2=@-2/@-1; *%.2f*
```

at the end of a table e.g., about the grand total of an addition
(there are other/better ways to achieve this).

The instruction however computes the ratio, and formats twice the
result; once for the number of decimals displayed (which is not the
adjustable precision of computation), followed by the addition
asterisks orgmode subsequently interprets to use bold glyphs.  So
eventually you concatenate characters, i.e. the content of the cell
no longer is of type integer, nor a real/floating number. Since an
addition in line of

```
A + 3.14 = ...
```

is not defined, Emacs reports an error.

My insight in Emacs calc still is too small to know how to to trim
character strings (i.e., remove of the asterisks) and convert a
string of characters like ```3.14``` into a floating number.  So
there might be better solutions than the following.

Let's use your idea to use /multiple table formulae/.  Contrasting to
your attempt, I don't mind to go the extra mile and to run a cheap
computation twice for a result already in hand.  As a MWE 

```
| quantity  |  value |
| A         |      1 |
| B         |      3 |
| ratio A/B | *0.33* |
| ratio + 1 |   1.33 |
#+TBLFM: @4$2 = @2/@3; *%.2f* :: @5$2 = @2/@3 + 1; %.2f
```

where the table is populated/updated by ```C-u C-c *```.

-8><---
Side note:  It is possible to experiment with multiple table formulae
on multiple lines, e.g. to use here

```
#+TBLFM: @4$2 = @2/@3; *%.2f*
#+TBLFM: @5$2 = @2/@3 + 1; %.2f
```

instead.  This may be fine at the level to join the nuts and bolts,
to populate (and update) the table TBLFM by TBLFM with an individual
```C-c C-c``` while the cursor is in the corresponding definition.
The example below however suggests ```C-u C-c *``` considers only the
first TBLFM and skips the other:

```
cave!  incomplete update by C-u C-c *

| quantity  |  value |
| A         |     20 |
| B         |      3 |
| ratio A/B | *6.67* |
| ratio + 1 |   1.33 |
#+TBLFM: @4$2 = @2/@3; *%.2f*
#+TBLFM: @5$2 = @2/@3 + 1; %.2f
```

Norwid


reply via email to

[Prev in Thread] Current Thread [Next in Thread]