Giter Site home page Giter Site logo

Comments (4)

dey-dey avatar dey-dey commented on May 14, 2024 3

Just a thought, but I would add here that while forcing the responsibility on lib users to do their own float conversion minimizes complexity for go-money, it also seems handling it in the library itself could prevent a lot of user error. Having a well-tested package that exports conversion functionality would relieve users of the library of a lot of duty they may not be knowledgable enough to have, especially for those new to Go. It's a decent enough use case to take these integers and display/work with floats on the frontend, so it would be nice to have this handled in an authoritative library and not have every lib user think about it.

from go-money.

Rhymond avatar Rhymond commented on May 14, 2024

Hi @vendion,

Why you see problem using 350 instead of 3.50?
By the way, floating-points and currency are working well together.

"If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- Bill Karwin

if your project requires usage of float, go-money shouldn't be responsible for type conversion. My suggestion would be to do type conversion inside your project (if required)

from go-money.

vendion avatar vendion commented on May 14, 2024

So some of the issues I see with taking ints are: 1) 350 isn't as obvious as 3.50 if hardcoded (for whatever reason that may be) at first glance it's impossible to know if that's three hundred and fifty, or three dollars (or insert your currency here) and fifty cents. 2) It is fairly common, at least from my experience, to use a datatype similar to a float with fixed precession to store currency in a database (https://www.postgresql.org/docs/current/static/datatype-money.html).

One advantage Go's *big.Float has is the ability to set the precision on it as well https://golang.org/pkg/math/big/#Float.SetPrec so it could be set to a precision of 2 places if need be. So in the case of the Bill Karwin quote he would have either $999.99 or maybe $1000depending on the rounding mode (by default it's the latter https://play.golang.org/p/p2wKfpbiofy BTW). Although that may not be the best example.

I wasn't trying to say that this implementation was bad/wrong or anything, it just seems odd to me and when I was originally looking for a good way to handle currency, it seemed like *big.Float was suggested more often, and even used in another package to handle formatting currency https://github.com/leekchan/accounting#caution

from go-money.

vendion avatar vendion commented on May 14, 2024

Anyways, closing this as you pretty much answered my question with the fact that go-money won't handle conversions

from go-money.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.