Skip to content

Reject a camt amount with more than two decimal digits - #85

Open
SashaMIT wants to merge 1 commit into
viafintech:masterfrom
SashaMIT:codered-cents-digits
Open

SashaMIT wants to merge 1 commit into
viafintech:masterfrom
SashaMIT:codered-cents-digits

Conversation

@SashaMIT

Copy link
Copy Markdown

Summary

to_amount_in_cents("30.123") returned 30123. The digits after the separator are concatenated, so a third decimal makes the cent amount ten times too large. More than two digits now raises. 30.12 is still 3012, 30,12 is still 3012, 1 is still 100, and 30.1 is still 3010.

Test plan

  • On master, to_amount_in_cents("30.123") returns 30123
  • On this branch it raises ArgumentError, and the conversions above still match

Made with Cursor

to_amount_in_cents("30.123") returned 30123. A third decimal digit made the cent amount ten times too large.
@tobischo

tobischo commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for the contribution.

Did you consider that there are currencies with more than 2 decimals? This solution would effectively break those, even if they are less likely to sit in camt files in the sepa area. However that is not impossible.

On the other hand the method is called amount in cents, which by definition should be just multiplied by 100

Also ljust codes it to 2 decimals already.

Could you share a bit more about the scenario in which this came up for you?

@SashaMIT

Copy link
Copy Markdown
Author

Thanks for looking at this.

The case I hit is to_amount_in_cents("30.123"). split gives cents "123", and ljust(2, "0") leaves that as-is, so the result is 30123. That is not 30.123 times 100. 30.12 still comes back as 3012, and 30.1 as 3010.

You're right that the name is cents, so two decimal digits are the contract. A currency with three decimals is a real exception, and this raise would reject it. I don't have a camt file in one of those currencies. The input I was looking at was a two-decimal amount with an extra digit, which came out ten times too large.

Happy to adjust if you'd rather scale by the currency's exponent, or leave three-decimal values alone. The part I wanted to stop is an extra digit being concatenated into the integer.

@tobischo

Copy link
Copy Markdown
Collaborator

So you used the method as a helper independent of a corresponding file?

What's the background of the number having 3 decimals in the context of your usage?

@SashaMIT

Copy link
Copy Markdown
Author

Yes. I called to_amount_in_cents on its own, not from a parsed camt file.

30.123 was a made-up amount so I could see what the extra digit did. I do not have a file where a three-decimal currency shows up. If you want those amounts to keep working, this raise is the wrong cut and I can drop it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants