all messages for Emacs-related lists mirrored at yhetil.org
 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

* Re: Org table: numeric locale
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Maxim Nikulin @ 2021-08-28 10:19 UTC (permalink / raw)
  To: emacs-orgmode

On 28/08/2021 14:07, Jarmo Hurri wrote:
> 
> I wonder if it is possible to get org table formulas to respect numeric
> locale.

Even to add some functions to Emacs that respect numeric locales, it is 
necessary to use e.g. dynamic modules (warning: do not try to change 
global locale by setlocale(3), almost certainly something in Emacs will 
be broken, a library that allows local locale objects is strongly 
preferred).
https://www.gnu.org/software/emacs/manual/html_node/elisp/Writing-Dynamic-Modules.html

> Emacs documentation says that Emacs uses the value of LC_NUMERIC:
> 
> https://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html

It is a confusing statement, see:
- https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29645
   #29645 Feature Request: Locale aware formatting
   Date: Sun, 10 Dec 2017 15:05:02 UTC
- https://lists.gnu.org/archive/html/emacs-devel/2021-06/msg00327.html
   https://lists.gnu.org/archive/html/emacs-devel/2021-06/msg00139.html

The state of numeric locales in Emacs is a little worse than just 
unsupported. Mostly "C" is forced for LC_NUMERIC, so e.g. grouping is 
not used. However if your locale uses comma "," as decimal separator,
you may be confused by calc results:

     M-x calc RET dg RET 123456
     123,456



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

* Re: Org table: numeric locale
  2021-08-28 10:19 ` Maxim Nikulin
@ 2021-09-05 11:08   ` Jarmo Hurri
  2021-09-07 14:47     ` Max Nikulin
  0 siblings, 1 reply; 4+ messages in thread
From: Jarmo Hurri @ 2021-09-05 11:08 UTC (permalink / raw)
  To: emacs-orgmode

Maxim Nikulin <manikulin@gmail.com> writes:

> On 28/08/2021 14:07, Jarmo Hurri wrote:
>> I wonder if it is possible to get org table formulas to respect
>> numeric locale.
>
> Even to add some functions to Emacs that respect numeric locales, it
> is necessary to use e.g. dynamic modules

>> Emacs documentation says that Emacs uses the value of LC_NUMERIC:
>> https://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html
>
> It is a confusing statement, see:
> - https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29645
>   #29645 Feature Request: Locale aware formatting
>   Date: Sun, 10 Dec 2017 15:05:02 UTC
> - https://lists.gnu.org/archive/html/emacs-devel/2021-06/msg00327.html
>   https://lists.gnu.org/archive/html/emacs-devel/2021-06/msg00139.html
>
> The state of numeric locales in Emacs is a little worse than just
> unsupported. Mostly "C" is forced for LC_NUMERIC, so e.g. grouping is
> not used.

I see. I am surprised by the disparity between documentation and
reality, given the quality I have learned to associate with emacs.

Thank you very much,

Jarmo



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

* Re: Org table: numeric locale
  2021-09-05 11:08   ` Jarmo Hurri
@ 2021-09-07 14:47     ` Max Nikulin
  0 siblings, 0 replies; 4+ messages in thread
From: Max Nikulin @ 2021-09-07 14:47 UTC (permalink / raw)
  To: emacs-orgmode

On 05/09/2021 18:08, Jarmo Hurri wrote:
> Maxim Nikulin writes:
>> On 28/08/2021 14:07, Jarmo Hurri wrote:
> 
>>> Emacs documentation says that Emacs uses the value of LC_NUMERIC:
>>> https://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html
>>
>> It is a confusing statement, see:
>> - https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29645
>>    #29645 Feature Request: Locale aware formatting
...
> I see. I am surprised by the disparity between documentation and
> reality, given the quality I have learned to associate with emacs.

You may report a documentation-related bug to debbugs.gnu.org. Far in 
the past there were some changes in the code, maybe update of 
documentation was forgotten.

src/ChangeLog.6

1996-04-08  Richard Stallman  <rms@mole.gnu.ai.mit.edu>
         (x_term_init): Restore LC_TIME as well as LC_NUMERIC.
1995-07-16  Richard Stallman  <rms@gnu.ai.mit.edu>
	(x_term_init) [HAVE_X11XTR6]: Set LC_NUMERIC and LC_TIME back to C.

Git archeology may provide more detailed info, though I have not tried.




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