Format currency amounts in fare_products.txt with 2 decimal digits #320
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Currently, these modules will incorrectly convert FareProduct amounts to output with an incorrect number of decimal places. For example, "2.50" will be converted to "2.5" when using the transformer or merger CLI. This results in the validation error https://gtfs-validator.mobilitydata.org/rules.html#invalid_currency_amount-rule.
This PR fixes the issue by treating the value as a Java Currency object, then using the CurrencyInstance of DecimalFormatter (stripped of the currency symbol) that produces a string format with the correct number of decimal places based on the currency.
Expected behavior:
amount
field in fare_products.txt will include 0 or 2 decimal places, depending on currency specified. It will "correct" the input as long as it can successfully parse as a decimal number.