Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Decimal Mark Handling after CSV Import with Rules #2195

Closed
yse opened this issue Apr 15, 2024 · 2 comments
Closed

Inconsistent Decimal Mark Handling after CSV Import with Rules #2195

yse opened this issue Apr 15, 2024 · 2 comments
Labels

Comments

@yse
Copy link

yse commented Apr 15, 2024

Environment:

  • hledger version: 1.32.1-g39fc78a64-20231207, mac-x86_64

Steps to Reproduce:

  1. Obtain the sample.csv and sample.csv.rules files from the examples directory on GitHub.
  2. Import transactions from sample.csv using the command:
hledger import --rules-file=sample.csv.rules --file transaction.ledger sample.csv
  1. Append a transaction with higher precision decimals to sample.csv:
echo '"2024/4/1","blah","-10000.00"' >> sample.csv
  1. Verify the transaction in transaction.ledger. The decimal mark appears correctly:
2024-04-01 blah
    assets:bank:checking      $-10000.00
    expenses:unknown           $10000.00
  1. Manually add a transaction with a comma as the thousand separator in transaction.ledger:
cat <<EOF >> transaction.ledger
2024-04-14 blahblah blah
    assets:bank:checking    \$2,000.00
    income:unknown          \$-2,000.00
EOF
  1. Append another transaction to sample.csv:
echo '"2024/4/15","blah blah","-2000.00"' >> sample.csv
  1. Re-import the updated CSV:
hledger import --rules-file=sample.csv.rules --file transaction.ledger sample.csv
  1. Review the latest transaction in transaction.ledger and observe the incorrect and unexpected use of a comma as the thousand separator:
2024-04-15 blah blah
    assets:bank:checking      $-2,000.00
    expenses:unknown           $2,000.00

Expected Behavior:

The decimal mark handling should remain consistent across manual entries and CSV imports, respecting the formatting defined in the rules file or the default behavior of the system.

Actual Behavior:

Transactions imported from the CSV file after manually appending entries with a different decimal format in the ledger file show an unexpected change in the decimal mark format (introduction of a comma as the thousand separator).

@simonmichael
Copy link
Owner

simonmichael commented Apr 15, 2024

Thanks for reporting!

Is the behaviour explained and justified by this:

import tries to follow the journal's existing commodity styles when it creates new entries.
During the first import, the journal contains no thousand commas, so the style for $ is no commas.
During the second import, because of the one thousand comma you added to the journal, the style with thousand commas is inferred for $, and used for the new entry.

Either avoiding adding unwanted thousand commas in the journal, or declaring the desired style explicitly in the journal with

commodity $1000.00

will prevent it.

@yse
Copy link
Author

yse commented Apr 17, 2024

Thanks a lot for clarifying. I've just used only D directive. Commodity also specify style for reporting which is impressive.

Thank you for this remarkably beautiful and useful tool.

@yse yse closed this as completed Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants