goodeggs / goodeggs-money

Reliable money math with BigNumber wrapped inside Cents
MIT License
3 stars 0 forks source link

Proposal: make the interface expect Dollars #3

Open brycefisher opened 7 years ago

brycefisher commented 7 years ago

In the handful of places I've personally used this module, I've nearly always been starting from and ending with dollars, not cents. I imagine that many others who use this feel the same way?

My proposal would be to change from this kind of usage:

Cents = require 'goodeggs-money'
price = Cents.fromDollars(15.99).plus(Cents.fromDollarys(1.60)).toDollars()

to something like this:

Dollars = require 'goodeggs-money' # or maybe require('goodeggs-money').Dollars for a nonbreaking change
price = Dollars(15.99).plus(1.60).toNumber()

Haven't thought too deeply about the implementation of this change, but it feels like the API I would want.

For what it's worth, this is much closer to API for the currency.js module that I quite like.

Thoughts?

sylspren commented 7 years ago

fwiw I prefer cents to avoid thinking about number precision. Cents are the lowest unit we can track and its easy to see you are using it correctly - pass in an integral amount.

asalant commented 7 years ago

Agree with Lei. We want to move to using cents everywhere to remove the confusion & impedance mismatch that Bryce describes. Cents being the primary interface to goodeggs-money is the opinioned way to express this.

On Fri, Dec 9, 2016 at 1:34 PM, Lei notifications@github.com wrote:

fwiw I prefer cents to avoid thinking about number precision. Cents are the lowest unit we can track and its easy to see you are using it correctly

  • pass in an integral amount.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/goodeggs/goodeggs-money/issues/3#issuecomment-266129625, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGwuEd4MfzpaEV4bMDVMO5qEwn1InXMks5rGclYgaJpZM4LJJJY .

-- Alon Salant | Good Eggs

dig in: market https://www.goodeggs.com/sfbay/home | seasonal recipes https://www.goodeggs.com/sfbay/seasonal-recipes | instagram https://instagram.com/goodeggs/