From: Jarmo Hurri <jarmo.hurri@iki.fi>
To: emacs-orgmode@gnu.org
Subject: Org table: numeric locale
Date: Sat, 28 Aug 2021 10:07:19 +0300 [thread overview]
Message-ID: <8735qut5co.fsf@iki.fi> (raw)
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
# -------------------------------------------------------------------------
next reply other threads:[~2021-08-28 7:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-28 7:07 Jarmo Hurri [this message]
2021-08-28 10:19 ` Org table: numeric locale Maxim Nikulin
2021-09-05 11:08 ` Jarmo Hurri
2021-09-07 14:47 ` Max Nikulin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8735qut5co.fsf@iki.fi \
--to=jarmo.hurri@iki.fi \
--cc=emacs-orgmode@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.