Wrong entry pointed out in "Too many commas in amount" error message

35 views
Skip to first unread message

Perl Ancar

unread,
Jun 4, 2021, 8:47:38 AM6/4/21
to Ledger
Hi everyone,

First of all, sorry I haven't updated ledger to the latest when testing this bug. I'm using 3.1.3-20190331 which comes with Ubuntu 20.04.2 LTS on my laptop. So perhaps this bug no longer exists.

ledger points out the wrong entry (probably the next entry with multiple commas) when there is a misplaced comma. Example:

    ; -*- Mode: ledger -*-

    2021/01/06 entry1
     assets:cash:savings:bca  200,0000 IDR
     assets:cash:dana

    2021/01/06 entry2
     assets:cash:savings:bca  100,000 IDR
     assets:cash:dana

    2021/01/06 entry3
     assets:cash:savings:bca  3,050,000 IDR
     assets:cash:dana

As you can see, the error is in entry1 in line 4. The amount should be "200,000 IDR" (extraneous 0) or perhaps 2,000,000 IDR (misplaced commas). But when run through ledger, it complains as follow:

    While parsing file "/home/u1/tmp/1.dat", line 12:
    While parsing posting:
      assets:cash:savings:bca  3,050,000 IDR
                               ^^^^^^^^^^^^^
    Error: Too many commas in amount

Regards,

Yuri Khan

unread,
Jun 4, 2021, 9:23:36 AM6/4/21
to Ledger
On Fri, 4 Jun 2021 at 19:47, Perl Ancar <perl...@gmail.com> wrote:

> ledger points out the wrong entry (probably the next entry with multiple commas) when there is a misplaced comma. Example:
>
> ; -*- Mode: ledger -*-
>
> 2021/01/06 entry1
> assets:cash:savings:bca 200,0000 IDR
> assets:cash:dana
>
> 2021/01/06 entry2
> assets:cash:savings:bca 100,000 IDR
> assets:cash:dana
>
> 2021/01/06 entry3
> assets:cash:savings:bca 3,050,000 IDR
> assets:cash:dana
>
> As you can see, the error is in entry1 in line 4. The amount should be "200,000 IDR" (extraneous 0) or perhaps 2,000,000 IDR (misplaced commas).

How do you figure that?

Ledger is pretty flexible in its input syntax. In particular, it
supports both ‘.’ (American convention) and ‘,’ (European convention)
as the decimal separator. Absent any explicit indication in your file,
it probably interprets entry1 as a transaction for two hundred and
zero ten-thousandths, entry2 for one hundred and zero thousandths, and
entry3 as “three and fifty thousandths and wait, what? surely a number
cannot have two decimal separators”.

If you change the first occurrence of IDR this way:

2021/01/06 entry1
assets:cash:savings:bca 200,0000.00 IDR

then Ledger says:

While parsing posting:
assets:cash:savings:bca 200,0000.00 IDR
^^^^^^^^^^^^^^^
Error: Incorrect use of thousand-mark comma

I was under the impression that pre-declaring the commodity should
also have this effect, but I don’t see that having any effect on
Ledger 3.1.2:

commodity IDR
format 1,000.00 IDR

I also did not find a way to say that the comma is the thousand
separator and dot is the decimal separator without setting the default
precision to non-zero.

In my own use, I just don’t bother writing the thousand separators; a
typical day-to-day transaction in RUB is not large enough to warrant
digit grouping. But I see how you might want to, and how you might not
want decimals at all.

Martin Michlmayr

unread,
Jun 4, 2021, 9:37:08 AM6/4/21
to ledge...@googlegroups.com
* Perl Ancar <perl...@gmail.com> [2021-06-04 05:47]:
> ledger points out the wrong entry (probably the next entry with
> multiple commas) when there is a misplaced comma. Example:

Ledger uses the first entry to figure out the format, so if the first
entry is wrong you don't have a guarantee where an error will occur.

Look at the ledger output for these to see how ledger interprets your
format:

2021/01/06 entry1
assets:cash:savings:bca 200,0000 IDR
assets:cash:dana

2021/01/06 entry2
assets:cash:savings:bca 100,000 IDR
assets:cash:dana

2021/01/06 entry4
assets:cash:savings:bca 1 IDR
assets:cash:dana

--
Martin Michlmayr
https://www.cyrius.com/

Perl Ancar

unread,
Jun 7, 2021, 7:33:04 AM6/7/21
to Ledger
I was completely oblivious to the fact that Ledger is flexible with regards to thousand separator and decimal point character. But even after I add a non-ambiguous "predeclaration" like this:

2021/01/01 entry0
 assets:cash:savings:bca  0,000,000.00 IDR

 assets:cash:dana

2021/01/06 entry1
 assets:cash:savings:bca  200,0000 IDR
 assets:cash:dana

2021/01/06 entry2
 assets:cash:savings:bca  100,000 IDR
 assets:cash:dana

2021/01/06 entry3
 assets:cash:savings:bca  3,050,000 IDR
 assets:cash:dana

I still can't make Ledger detect the error in entry1. It still ends up complaining about entry3. If entry1 is commented out, Ledger now can parse the file and correctly use the format specified by entry0:

% ledger -f 2.dat bal
                   0  assets:cash
   -3,150,000.00 IDR    dana
    3,150,000.00 IDR    savings:bca
--------------------

In my own use, I just don’t bother writing the thousand separators; a
typical day-to-day transaction in RUB is not large enough to warrant
digit grouping. But I see how you might want to, and how you might not
want decimals at all.

 With the relatively low monetary value of IDR, it's quite helpful as the numbers can easily go into hundreds of millions or billions. Without the thousand grouping I would have made even more errors.

Regards,
perlancar

Perl Ancar

unread,
Jun 7, 2021, 7:34:03 AM6/7/21
to Ledger
Hi Martin,

What command do you use to show how Ledger parses a file, like the above?

Regards,
perlancar

Martin Michlmayr

unread,
Jun 15, 2021, 3:39:15 AM6/15/21
to ledge...@googlegroups.com
* Perl Ancar <perl...@gmail.com> [2021-06-07 04:34]:
> > 2021/01/06 entry4
> > assets:cash:savings:bca 1 IDR
> > assets:cash:dana
>
> What command do you use to show how Ledger parses a file, like the above?

I'm not sure. What I meant is to run "ledger reg" on the example I
provided. It would have shown how it's processed.
Reply all
Reply to author
Forward
0 new messages