emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org table: numeric locale
@ 2021-08-28  7:07 Jarmo Hurri
  2021-08-28 10:19 ` Maxim Nikulin
  0 siblings, 1 reply; 4+ messages in thread
From: Jarmo Hurri @ 2021-08-28  7:07 UTC (permalink / raw)
  To: emacs-orgmode


Greetings.

I wonder if it is possible to get org table formulas to respect numeric
locale.

Emacs documentation says that Emacs uses the value of LC_NUMERIC:

https://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html

However, even though I have a value of LC_NUMERIC which specifies comma
as a decimal separator, I get dot as a decimal separator when formatting
a floating point value in both elisp and in org table formula. So yes, I
am aware that the source of the issue is likely to be in Emacs, but I
only need a solution for org only.

The example at the end of this message tries to illustrate all aspects:
what my environment variables are, what Emacs sees and does, what org
does, and how to force locale in another language (C++).

Have fun and stay safe,

Jarmo

# -------------------------------------------------------------------------
* My relevant locale variables in shell
  #+begin_src sh
    echo "LANG: ${LANG}"
    echo "LC_ALL: ${LC_ALL}"
    echo "LC_NUMERIC: ${LC_NUMERIC}"
  #+end_src

  #+RESULTS:
  | LANG:       | en_GB.UTF-8 |
  | LC_ALL:     |             |
  | LC_NUMERIC: | fi_FI.UTF-8 |

* What emacs sees and does
  Emacs uses dot, not comma, as decimal separator.
  #+begin_src elisp
    (let ((env (mapconcat 'getenv (list "LANG" "LC_ALL" "LC_NUMERIC") " "))
          (str (format "%.2f" (/ 1.0 3))))
      (concat env "\n" str "\n" (emacs-version)))
  #+end_src

  #+RESULTS:
  : en_GB.UTF-8  fi_FI.UTF-8
  : 0.33
  : GNU Emacs 27.2 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.24.30, cairo version 1.17.4)
  :  of 2021-08-07

* What Org table does
  Org table also uses dot, not comma, as decimal separator.
  | 0.33 |
  #+TBLFM: @1$1=1.0/3;%.2f

* C++ version (for comparison)
  #+begin_src C++ :results raw
    #include <cstdlib>
    #include <cstdio>
    #include <clocale>
    
    int main (int argc, char* argv[])
    {
        // I have to set locale, it is not obtained automatically from
        // shell environment
        setlocale (LC_NUMERIC, getenv ("LC_NUMERIC"));
    
        printf ("%.2f", 1.0 / 3);
        exit (0);
    }
  #+end_src

  #+RESULTS:
  0,33
# -------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-07 14:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28  7:07 Org table: numeric locale Jarmo Hurri
2021-08-28 10:19 ` Maxim Nikulin
2021-09-05 11:08   ` Jarmo Hurri
2021-09-07 14:47     ` Max Nikulin

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).