currency.js icon indicating copy to clipboard operation
currency.js copied to clipboard

Add a .inCents() function

Open graemetavour opened this issue 3 years ago • 3 comments

If you need to access the underlying value in cents (for instance to persist to a database or use in an API call), currently you need to use:

currency(valueInDollars).intValue;

It would be slightly more clear to be able to use:

currency(valueInDollars).inCents();

Not sure if inCents() is the best naming; could also consider toCentValue(), centValue(), valueInCents(), etc

graemetavour avatar Sep 10 '21 19:09 graemetavour

'subUnits' might be better to help remove api references to the US dollar/cents.

MikesGlitch avatar Oct 21 '22 19:10 MikesGlitch

How about currency(valueInMajorUnits).minorUnits?

raldred avatar Jan 20 '23 23:01 raldred

If you had a precision > 2, then currency(valueInDollars).intValue would not equal cents either.

alexlukelevy avatar Jul 19 '23 22:07 alexlukelevy