[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/csv2ledger 4f6bb9e1bd 184/190: Update example function jk/
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/csv2ledger 4f6bb9e1bd 184/190: Update example function jk/c2l-convert-amount in the README |
Date: |
Sun, 2 Jun 2024 16:00:01 -0400 (EDT) |
branch: elpa/csv2ledger
commit 4f6bb9e1bd7d634c6bfa2c1940ebfeaa742c1032
Author: Joost Kremers <joostkremers@fastmail.com>
Commit: Joost Kremers <joostkremers@fastmail.com>
Update example function jk/c2l-convert-amount in the README
---
README.md | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 07bae19bfe..2d129bee8f 100644
--- a/README.md
+++ b/README.md
@@ -162,12 +162,15 @@ Since this is a very particular conversion, there is no
function for it included
```emacs-lisp
(defun jk/c2l-convert-amount (amount)
- "Convert AMOUNT from the format \"-3.150,20 €\" to \"-€3150.20\"."
- (string-match
"\\(-\\)?\\([[:digit:].]+\\)\\(?:,\\([[:digit:]]\\{2\\}\\)\\)?" amount)
+ "Convert AMOUNT from the format \"-3.150,20 €\" to \"-€3150.20\".
+This also handles cases such as \"300\" and \"8,7\"."
+ (string-match "\\(-\\)?\\([[:digit:].]+\\(?:,[[:digit:]]\\{2\\}\\)?\\)"
amount)
(let ((sign (or (match-string 1 amount) ""))
- (euros (string-replace "." "" (match-string 2 amount)))
- (cents (or (match-string 3 amount) "00")))
- (concat sign "€" euros "." cents)))
+ (amount (thread-last (match-string 2 amount)
+ (string-replace "." "")
+ (string-replace "," ".")
+ string-to-number)))
+ (format "%s€%.2f" sign amount)))
```
The setting for `c2l-field-modify-functions` then ends up like this:
- [nongnu] elpa/csv2ledger 058bd5c96d 148/190: Declare safety predicates for defcustoms., (continued)
- [nongnu] elpa/csv2ledger 058bd5c96d 148/190: Declare safety predicates for defcustoms., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 8b5aa6ee00 156/190: Fix two typos in the documentation, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger c8939a4422 188/190: Fix c2l-read-account-matchers, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 03e33d295f 107/190: Replace README with a placeholder., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 1ab230f07d 181/190: Update doc string of c2l--csv-line-to-ledger, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 579acc2d00 032/190: Do not require a match when asking for an account name., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 80e39156a9 101/190: Fix c2l-amount-is-amount., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 463fa78c33 047/190: Rename internal functions with double dash., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger eb05c12358 183/190: Fix typo in the README, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 7cc8fa2ecf 182/190: Update version number., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 4f6bb9e1bd 184/190: Update example function jk/c2l-convert-amount in the README,
ELPA Syncer <=
- [nongnu] elpa/csv2ledger be1366e6d4 031/190: c2l-payee-or-sender: first check if `c2l-account-holder` is even set., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger eaf2ad4fee 028/190: Do not test if file exists if file is nil., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger ac7abd896f 092/190: Guard against empty value of counterpart., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger d5f5712969 083/190: Add comment indicating interactive functions., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 6fa69d4391 089/190: Rename regexes to regexps in the source., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger e08f335190 091/190: Change fallback value of c2l-title-is-payee-to-sender., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 1048cf77d9 095/190: Update the README., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 8f1c8fa2b6 090/190: Guard for the case where payee or sender does not exist., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 95e107e9bd 123/190: Nicify the README a bit., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger c558f2bf40 176/190: Add alternative account creation function c2l-create-account-ask-matcher, ELPA Syncer, 2024/06/03