emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [feature] Allow "," decimal point in table cells


From: Ihor Radchenko
Subject: Re: [feature] Allow "," decimal point in table cells
Date: Wed, 20 Jul 2022 21:19:11 +0800

Uwe Brauer <oub@mat.ucm.es> writes:

>> Note that you can instead use Elisp formulas. See 3.5.3 Emacs Lisp forms
>> as formulas. It is more flexible.
>
> Can you give me an example?

#+begin_src emacs-lisp
(defun yant/convert-cd (x)
  "Replace \",\" in X string with \".\" and return number."
  (string-to-number (replace-regexp-in-string "," "." x)))
(defun yant/convert-dc (x)
  "Replace \".\" in X number with \",\" and return string."
  (replace-regexp-in-string "\\." "," (format "%s" x)))
#+end_src

| 3,5 | 4,2 | 7,7 |
#+TBLFM: $3='(yant/convert-dc (apply '+ (mapcar #'yant/convert-cd (list $1 
$2))))

Yes, it is awkward. Yet possible.

>> Alternatively, we may implement the comma separators as a built-in
>> feature. Org table formulas already support notations like
>
>> | 3,5 | 4,2 | 7 |
>
>> #+TBLFM: $3=$1+$2;N
>
> Not sure I understand this 
>
> | 3,5 | 4,2 | 7 | (7, 7) | (7, 7) |
> |     |     |   |        |        |
> #+TBLFM: $3=$1+$2;N::$4=$1+$2;E::$5=$1+$2;L

;N means "convert to number using string-to-number".
(string-to-number "3,5") ;; => 3
why? read the docstring (it ignores non-recognized trailing chars ",5")

L makes no sense in calc formulas (it has no effect).

E refers to dealing with empty field and has no effect here.

Best,
Ihor



reply via email to

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