emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Allow Currency Symbols and Grouping Commas in Table Numbers


From: Daniel E. Doherty
Subject: Re: Allow Currency Symbols and Grouping Commas in Table Numbers
Date: Fri, 27 May 2022 08:49:47 -0500
User-agent: mu4e 1.6.2; emacs 29.0.50

On Fri, May 27 2022, Ihor Radchenko wrote:

Ihor, thanks for your thoughts, but this does not solve my problem.

Here is an sample org table that exemplifies the problem:

==================================================
#+begin_SRC emacs-lisp
  (setq org-calc-default-modes
    '(calc-internal-prec 12
             calc-float-format  (float 8)
             calc-angle-mode    deg
             calc-prefer-frac   nil
             calc-symbolic-mode nil
             calc-language latex ;; <--- this is new compared to default
             calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" mm))
             calc-display-working-message t))
#+end_SRC

#+RESULTS:
| calc-internal-prec | 12 | calc-float-format | (float 8) | calc-angle-mode | 
deg | calc-prefer-frac | nil | calc-symbolic-mode | nil | calc-language | latex 
| calc-date-format | (YYYY - MM - DD   Www (  hh : mm)) | 
calc-display-working-message | t |


| Description  | Amount          |
|--------------+-----------------|
| Mortage      | $125,000.26     |
| Credit Cards | 6,325.00        |
| Auto Loan    | 14,853.00       |
|--------------+-----------------|
| Total        | :=vsum(@I..@II) |
#+TBLFM: @5$2=vsum(@I..@II)

-> Error: Invalid field specifier "$125"

| Description  |    Amount |
|--------------+-----------|
| Mortage      | 125000.26 |
| Credit Cards |   6325.00 |
| Auto Loan    |  14853.00 |
|--------------+-----------|
| Total        | 146178.26 |
#+TBLFM: @5$2=vsum(@I..@II)


| Description  | Amount     |
|--------------+------------|
| Mortage      | 125,000.26 |
| Credit Cards | 6,325.00   |
| Auto Loan    | 14,853.00  |
|--------------+------------|
| Total        | 1323.26    |
#+TBLFM: @5$2=vsum(@I..@II)

Note that the total is wrong.


| Description  | Amount                     |
|--------------+----------------------------|
| Mortage      | \dollar 125000.26          |
| Credit Cards | 6325.00                    |
| Auto Loan    | 14853.00                   |
|--------------+----------------------------|
| Total        | 125000.26 \dollar + 21178. |
#+TBLFM: @5$2=vsum(@I..@II)

Total is still wrong.
============================================
>
> You can, for example, do
>
> | 1 USD | 2 USD | 4 USD | 7 USD |
>
> #+tblfm: $4=vsum($1..$3)
>
> Emacs calc is able to work with arbitrary ascii symbols or even units.
> However, calc does not appear work with unicode. If Emacs calc were to
> support unicode, it would automatically work in Org.
>
> Also, you can
>
> enable latex in calc via
> (setq org-calc-default-modes
>   '(calc-internal-prec 12
>                      calc-float-format  (float 8)
>                      calc-angle-mode    deg
>                      calc-prefer-frac   nil
>                      calc-symbolic-mode nil
>                        calc-language latex ;; <--- this is new compared to 
> default
>                      calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" 
> mm))
>                      calc-display-working-message t))
>

But it requires the \dollar on every entry.  The convention if
financial table is to include the currency symbol only on the first
item.

> Then, the following will work
>
> | \dollar1 | \dollar2 | \dollar3 | 6 \dollar |
>
> #+tblfm: $4=vsum($1..$3)

Whatever calc is able to handle, calc is not getting the entries
interpreted as numbers, or at least not the numbers that a human would
understand.

My elisp skills are limited, but it seems that org mode could, as a
matter of course, strip commas and currency symbols from the numbers
before delivering them to calc, and, if the user wants add back the
grouping commas and currency symbol with a format specifier in the
result.

Also, it would be better if the regular expression for recognizing
numbers allowed grouping commas and currency symbols to be included by
default so that financial-type numbers get right-aligned by default.

>
> Best,
> Ihor


--
====================================================
Daniel E. Doherty
Law Offices of Daniel E. Doherty
7300 W. 110th Street, Suite 930
Overland Park, KS 66210
913.338.7182 (Phone)
913.338.7164 (FAX)
ded@ddoherty.net



reply via email to

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