summaryrefslogtreecommitdiff
path: root/lisp/ledger-commodities.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ledger-commodities.el')
-rw-r--r--lisp/ledger-commodities.el23
1 files changed, 7 insertions, 16 deletions
diff --git a/lisp/ledger-commodities.el b/lisp/ledger-commodities.el
index e6f5417d..c2d7639b 100644
--- a/lisp/ledger-commodities.el
+++ b/lisp/ledger-commodities.el
@@ -33,11 +33,6 @@
:type 'string
:group 'ledger-reconcile)
-(defcustom ledger-scale 10000
- "The 10 ^ maximum number of digits you would expect to appear in your reports.
-This is a cheap way of getting around floating point silliness in subtraction"
- :group 'ledger)
-
(defun ledger-split-commodity-string (str)
"Split a commoditized string, STR, into two parts.
Returns a list with (value commodity)."
@@ -86,11 +81,7 @@ Returns a list with (value commodity)."
(defun -commodity (c1 c2)
"Subtract C2 from C1, ensuring their commodities match."
(if (string= (cadr c1) (cadr c2))
- ; the scaling below is to get around inexact
- ; subtraction results where, for example 1.23
- ; - 4.56 = -3.3299999999999996 instead of
- ; -3.33
- (list (/ (- (* ledger-scale (car c1)) (* ledger-scale (car c2))) ledger-scale) (cadr c1))
+ (list (-(car c1) (car c2)) (cadr c1))
(error "Can't subtract different commodities %S from %S" c2 c1)))
(defun +commodity (c1 c2)
@@ -100,22 +91,21 @@ Returns a list with (value commodity)."
(error "Can't add different commodities, %S to %S" c1 c2)))
(defun ledger-strip (str char)
- (let (new-str)
- (concat (dolist (ch (append str nil) new-str)
- (unless (= ch char)
- (setq new-str (append new-str (list ch))))))))
+ "Return STR with CHAR removed."
+ (replace-regexp-in-string char "" str))
(defun ledger-string-to-number (str &optional decimal-comma)
"improve builtin string-to-number by handling internationalization, and return nil if number can't be parsed"
(let ((nstr (if (or decimal-comma
(assoc "decimal-comma" ledger-environment-alist))
- (ledger-strip str ?.)
- (ledger-strip str ?,))))
+ (ledger-strip str ".")
+ (ledger-strip str ","))))
(while (string-match "," nstr) ;if there is a comma now, it is a thousands separator
(setq nstr (replace-match "." nil nil nstr)))
(string-to-number nstr)))
(defun ledger-number-to-string (n &optional decimal-comma)
+ "number-to-string that handles comma as decimal."
(let ((str (number-to-string n)))
(when (or decimal-comma
(assoc "decimal-comma" ledger-environment-alist))
@@ -134,6 +124,7 @@ longer ones are after the value."
(concat commodity " " str))))
(defun ledger-read-commodity-string (prompt)
+ "Read an amount from mini-buffer using PROMPT."
(let ((str (read-from-minibuffer
(concat prompt " (" ledger-reconcile-default-commodity "): ")))
comm)