Emacs 如何在组织模式下将表字段格式化为货币

Emacs 如何在组织模式下将表字段格式化为货币,emacs,spreadsheet,currency,org-mode,Emacs,Spreadsheet,Currency,Org Mode,我想将组织模式表中的字段格式化为货币 -以货币符号($)和逗号作为千位分隔符表示。我一直在使用$%.2f来获取例如$1000.00,但是如何获取逗号分隔符例如$1000.00?我有RTFM,但可能我太密集了,无法得到它。calc或elisp公式都可以。见下表示例: | Item | Quantity | Price | Ext | |----------+----------+--------+----------| | Widget 1 | 10 | 100.0

我想将组织模式表中的字段格式化为货币 -以货币符号($)和逗号作为千位分隔符表示。我一直在使用$%.2f来获取例如$1000.00,但是如何获取逗号分隔符例如$1000.00?我有RTFM,但可能我太密集了,无法得到它。calc或elisp公式都可以。见下表示例:

| Item     | Quantity |  Price |      Ext |
|----------+----------+--------+----------|
| Widget 1 |       10 | 100.00 |  1000.00 |
| Widget 2 |        5 |  50.00 |   250.00 |
| Widget 3 |        1 |   5.00 |     5.00 |
|----------+----------+--------+----------|
|          |          |  Total | $1255.00 |
#+TBLFM: $4=($2*$3);%.2f::@5$4=vsum(@2..@4);$%.2f

我找不到一致的方法,这样你就可以得到带有数千个分隔符的数字,而这些数字会被正确地解释以供进一步计算。所以这不是一个答案,只是为了记录我到目前为止的研究

下面的示例演示如何使用数千个分隔符格式化数字<代码>C-C C-C在代码上定义函数,或添加到初始化文件

然后,使用elisp计算总计,并使用新的格式化函数进行转换

#+begin_src elisp :results none
(defun my-thousands-separate (num)
  "Formats the (possibly floating point) number with a thousands
separator."
  (let* ((nstr (number-to-string num))
         (dot-ind (string-match "\\." nstr))
         (nstr-no-decimal (if dot-ind
                               (substring nstr 0 dot-ind)
                             nstr))
         (nrest (if dot-ind
                    (substring nstr dot-ind)
                  nil))
         (pretty nil)
         (cnt 0))
    (dolist (c (reverse (append nstr-no-decimal nil)))
      (if (and (zerop (% cnt 3)) (> cnt 0))
          (setq pretty (cons ?, pretty)))
      (setq pretty (cons c pretty))
      (setq cnt (1+ cnt)))
    (concat pretty nrest)))
#+end_src

| Item     | Quantity |      Price |          Ext |
|----------+----------+------------+--------------|
| Widget 1 | 10       | 1001001.00 |  10010010.00 |
| Widget 2 | 5        |  501001.00 |   2505005.00 |
| Widget 3 | 1        |   51001.00 |     51001.00 |
|----------+----------+------------+--------------|
|          |          |      Total | 12,566,016.0 |
#+TBLFM: $4=($2*$3);%.2f::@5$4='(my-thousands-separate (apply '+ '(@2..@4)));N
请注意,如果对行总计执行相同的操作,则以逗号分隔的数字将无法正确解释总计

正确的方法应该是让printf来完成,但是我不知道如何为emacs设置这个