emacs-orgmode
[Top][All Lists]
Advanced

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

Org table: numeric locale


From: Jarmo Hurri
Subject: Org table: numeric locale
Date: Sat, 28 Aug 2021 10:07:19 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

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
# -------------------------------------------------------------------------




reply via email to

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