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

proposal: Go 2: introduce a money package #29134

Closed
tomask-de opened this issue Dec 7, 2018 · 4 comments
Closed

proposal: Go 2: introduce a money package #29134

tomask-de opened this issue Dec 7, 2018 · 4 comments
Labels
FrozenDueToAge Proposal v2 An incompatible library change
Milestone

Comments

@tomask-de
Copy link

Introduce a money package in Go2

Based on Martin Fowler:
A large proportion of the computers in this world manipulate money, so it's always puzzled me that money isn't actually a first class data type in any mainstream programming language. The lack of a type causes problems, the most obvious surrounding currencies. If all your calculations are done in a single currency, this isn't a huge problem, but once you involve multiple currencies you want to avoid adding your dollars to your yen without taking the currency differences into account. The more subtle problem is with rounding. Monetary calculations are often rounded to the smallest currency unit. When you do this it's easy to lose pennies (or your local equivalent) because of rounding errors.

The good thing about object-oriented programming is that you can fix these problems by creating a Money class that handles them. Of course, it's still surprising that none of the mainstream base class libraries actually do this.

https://martinfowler.com/eaaCatalog/money.html
https://martinfowler.com/bliki/CurrencyAsValue.html

@bronze1man
Copy link
Contributor

bronze1man commented Dec 7, 2018

How to design the money package?

I assume this proposal can only solve the money problem.
If this proposal need change the golang syntax, than it may make more problems than it solves. (like everyone use the golang need to learn this syntax to understand other's code)
If this proposal do not need change the golang syntax, then it will be better to implement outside GOROOT.

@ianlancetaylor ianlancetaylor changed the title proposel: Go 2: introduce a money package proposal: Go 2: introduce a money package Dec 7, 2018
@gopherbot gopherbot added this to the Proposal milestone Dec 7, 2018
@ianlancetaylor
Copy link
Contributor

Might be useful to look at the golang.org/x/text/currency package.

This proposal seems to lack an actual proposal. What API should the package provide?

@ianlancetaylor ianlancetaylor added the v2 An incompatible library change label Dec 7, 2018
@kardianos
Copy link
Contributor

I think you are talking less about currency and more about decimals. there are some existing issues such support.

If you have decimal needs right now, you may want to look into https://godoc.org/github.com/cockroachdb/apd .
Also related #19787 and #12127.

@ianlancetaylor
Copy link
Contributor

Thanks, but in order to move forward we need a specific proposal with an API. At the moment it seems to me that this can be done entirely in a library, and that library doesn't need to be in the standard library. Closing for now but please feel free to comment.

@golang golang locked and limited conversation to collaborators Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

5 participants