goodeggs / goodeggs-money

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

Unable to use `dividedBy()` on Cents #4

Open brycefisher opened 7 years ago

brycefisher commented 7 years ago

Repro case:

$ node
> var Cents = require('goodeggs-money')
> var tenDollars = new Cents(1000)
undefined
> tenDollars.dividedBy(tenDollars)
BigNumber Error: new BigNumber() not a number: $10.00
    at raise (/Users/bryce/node_modules/bignumber.js/bignumber.js:1181:25)
    at /Users/bryce/node_modules/bignumber.js/bignumber.js:1169:33
    at new BigNumber (/Users/bryce/node_modules/bignumber.js/bignumber.js:195:67)
    at BigNumber.P.dividedBy.P.div (/Users/bryce/node_modules/bignumber.js/bignumber.js:1455:31)
    at Cents.module.exports.Cents.dividedBy (/Users/bryce/node_modules/goodeggs-money/lib/index.js:127:33)
    at repl:1:12
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)

I was able to get it working thusly:

> tenDollars.dividedBy(tenDollars.toNumber())
Cents { value: 1 }

Given that the README indicates it safe to rewrap Cents, I assumed that dividedBy another Cents would work too.