hledger
hledger copied to clipboard
Allow for integer comparison on CSV import
From reading the following sections
https://hledger.org/1.26/hledger.html#setting-amounts https://hledger.org/1.26/hledger.html#regular-expressions
I think that a conditional %amount comparison against an integer it is not possible
This is a very nice to have feature since allows to quickly skip small transactions not worth putting effort into classifying. For instance, it would be nice to be able to do something like this (assuming we use a column called "amount" on the csv rules):
if %amount < 10
skip
I think that at the moment all variables are treated as strings, so some casting like below may be needed:
if int`(%amount) < 10
skip
Or maybe easier for the parser, create a new variable (which, BTW, it is not possible at the moment)
intamount int`(%amount)
if intamount < 10
skip
Or even real numbers ...
ramount real`(%amount)
if ramount < 7.63
skip
It is kind of possible, by using regular expressions. For example, this might work for matching amounts < 10:
if %amount ^-?[0-9]\b
But it's fragile, so I try to use it sparingly. Eg if I decide to download my bank data in a different way (manually, from bank's api, from plaid, etc.), numbers in CSV may have different format or sign, and my regexps and rules break.
I agree it would be nicer to have a more robust way to match amounts, such as hledger's amt: query.