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

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

pascaldekloe opened this issue Apr 13, 2016 · 5 comments

Comments

@pascaldekloe
Copy link
Contributor

@pascaldekloe pascaldekloe commented Apr 13, 2016

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

This comment has been minimized.

Copy link
Contributor Author

@pascaldekloe pascaldekloe commented Apr 13, 2016

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 13, 2016

CC @mpvl

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Apr 13, 2016
@pascaldekloe

This comment has been minimized.

Copy link
Contributor Author

@pascaldekloe pascaldekloe commented Apr 13, 2016

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

This comment has been minimized.

Copy link
Member

@mpvl 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

This comment has been minimized.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.