String with comma to decimal using D()

32 views
Skip to first unread message

Florian Lindner

unread,
Apr 26, 2019, 1:14:30 PM4/26/19
to Beancount

Hello,

https://aumayr.github.io/beancount-docs-static/api_reference/beancount.core.html?highlight=link#beancount.core.number.D says:

"Convert a string, possibly with commas, into a Decimal object."

However, feeding it a string with comma:

units = amount.Amount(D(row["Soll/Haben"]), "EUR") # .replace(",", "."), "EUR")
print(units, row["Soll/Haben"])

outputs:

-3000 EUR -30,00

D() seems to just swallow the comma, not use it as decimal separator, what I expect from the doc string. Doing a .replace(",", ".") works, but the documentation seems wrong or misleading.

Best Thanks,
Florian

Martin Michlmayr

unread,
Apr 26, 2019, 1:24:20 PM4/26/19
to bean...@googlegroups.com
* Florian Lindner <mailin...@xgm.de> [2019-04-26 10:14]:
> https://aumayr.github.io/beancount-docs-static/api_reference/beancount.core.html?highlight=link#beancount.core.number.D
> "Convert a string, possibly with commas, into a Decimal object."

> but the documentation seems wrong or misleading.

It's not wrong per se (although I can see how it can be viewed as
misleading if you're used to comma decimal separators). The comma is
used to separate thousands, e.g. 1,000,000.00 is one million.
beancount will handle that correctly.

> D() seems to just swallow the comma, not use it as decimal separator

Because comma decimal separators are currently not supported, see
https://bitbucket.org/blais/beancount/issues/204

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

Florian Lindner

unread,
Apr 27, 2019, 4:08:58 AM4/27/19
to Beancount

That's fair and I am ok without having support for the comma as decimal separator. Actually, I was not even expecting it, until I read the doc string. I think, if the documentation would be like


"Convert a string, possibly with commas as thousands separator, into a Decimal object."


it was more clear.


Best,

Florian

Martin Blais

unread,
Apr 27, 2019, 9:51:37 AM4/27/19
to Beancount

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/0f16a066-c06e-41ad-9057-b115bde43824%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Florian Lindner

unread,
Apr 30, 2019, 9:35:45 AM4/30/19
to bean...@googlegroups.com
Hello,
However, feeding it a string with comma:

units = amount.Amount(D(row["Soll/Haben"]), "EUR") # .replace(",", "."), "EUR")
print(units, row["Soll/Haben"])

outputs:

-3000 EUR -30,00

D() seems to just swallow the comma, not use it as decimal separator, what I expect from the doc string. Doing a .replace(",", ".") works, but the documentation seems wrong or misleading.

Best Thanks,
Florian


Reply all
Reply to author
Forward
0 new messages