emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Norwid Behrnd <nbehrnd@yahoo.com>
To: Jarmo Hurri <jarmo.hurri@iki.fi>
Cc: emacs-orgmode@gnu.org
Subject: Re: Org table: emphasizing calculated cell
Date: Fri, 27 Aug 2021 08:12:26 +0000	[thread overview]
Message-ID: <20210827081226.402ce8c3@carnot2> (raw)
In-Reply-To: <8735qvcyyy.fsf@iki.fi>

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	other threads:[~2021-08-27  8:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  5:47 Org table: emphasizing calculated cell Jarmo Hurri
2021-08-26  7:51 ` Norwid Behrnd
2021-08-27  4:07   ` Jarmo Hurri
2021-08-27  8:12     ` Norwid Behrnd [this message]
2021-08-28  4:42       ` Jarmo Hurri
2021-08-27 20:08     ` Nick Dokos
2021-08-27 22:05       ` Samuel Wales
2021-08-28  4:33       ` Jarmo Hurri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210827081226.402ce8c3@carnot2 \
    --to=nbehrnd@yahoo.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jarmo.hurri@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).