We frequently generate currency in Good Eggs code. Though we have a standard to manipulate currency as integer cents, we do also have legacy code that manipulates dollars as floats, and we also have a need to display currency as dollar strings.
I would propose:
fake.cents(): returns an integer from 1 to some large upper bound inclusively
- we do sometimes need negative cents like for a discount – should we default to positive but allow passing in a negative min? or default to negative? or make two separate methods? hmm
fake.dollars(): returns an integer from 0.00 to some large upper bound inclusively, with at most two decimal places
- callers can use
fake.dollars().toString() to generate a string representation of a dollar amount
- same question about negatives above applies as well
Alternatively, we could nest these together maybe: fake.money.{dollars,cents}?
I don't think I endorse this, but alternatively we could have one or more of these "cents" methods return an instance of BigNumber/Cents?
We frequently generate currency in Good Eggs code. Though we have a standard to manipulate currency as integer cents, we do also have legacy code that manipulates dollars as floats, and we also have a need to display currency as dollar strings.
I would propose:
fake.cents(): returns an integer from 1 to some large upper bound inclusivelyfake.dollars(): returns an integer from 0.00 to some large upper bound inclusively, with at most two decimal placesfake.dollars().toString()to generate a string representation of a dollar amountAlternatively, we could nest these together maybe:
fake.money.{dollars,cents}?I don't think I endorse this, but alternatively we could have one or more of these "cents" methods return an instance of BigNumber/Cents?