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

x/text/currency: add support for arbitrary-precision currency amounts #15274

Open
pascaldekloe opened this issue Apr 13, 2016 · 5 comments
Open
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@pascaldekloe
Copy link
Contributor

Add support for arbitrary-precision currency amounts with math/big. The interface as-is could handle things like currency.USD.Amount(big.Rat(1, 100)).

@pascaldekloe
Copy link
Contributor Author

I'm more than happy to implement both big.Rat and big.Float.

@ianlancetaylor
Copy link
Contributor

CC @mpvl

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Apr 13, 2016
@pascaldekloe
Copy link
Contributor Author

There are two ways to apply an amount: currency.Unit.Amount and directly with the currency.Formatter implementations. Both ways have a type validation TODO pending.
https://github.com/golang/text/blob/master/currency/currency.go#L82
https://github.com/golang/text/blob/master/currency/format.go#L161

How should the error handling be implemented? Is panic appropriate? As an alternative Unit.Amount could return an error or an ok boolean and the Formatter could print fmt style error strings.

@mpvl
Copy link
Contributor

mpvl commented May 21, 2016

More extensive number handling for numbers in general is being implemented in a separate package. Error handling should be handled in this separate package. big.* should be supported there too.

However, as long as there are no API changes I'm find with adding a provisional implementation to support the big.*. See format_test.go:TestFormatting to add test cases for these. Keep in mind this would be temporary code. If you need it now it will make sense to add it though.

Also note that for really proper and correct currency handling, we will need a decimal floating point type.

@ericlagergren
Copy link
Contributor

@ALTree ALTree changed the title x/text/currency arbitrary-precision currency amounts x/text/currency: add support for arbitrary-precision currency amounts Sep 22, 2018
@ALTree ALTree added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. FeatureRequest labels Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants