Convert a dollar amount to cents (smallest currency unit)
The currency's minor unit comes from ISO 4217 through minorUnitExponent in payments-core, matched in any case. A code outside CurrencyCode gets its own multiplier (1000 for KWD, 1 for KRW).
minorUnitExponent
CurrencyCode
KWD
KRW
Dollar amount (e.g., 10.50)
Currency code (default: USD)
Amount in smallest currency unit (e.g., 1050 for $10.50 USD)
When currency is not a string, or is empty or only whitespace
currency
toCents(10.50) // 1050toCents(10.50, 'USD') // 1050toCents(1000, 'JPY') // 1000 (JPY has no decimal places) Copy
toCents(10.50) // 1050toCents(10.50, 'USD') // 1050toCents(1000, 'JPY') // 1000 (JPY has no decimal places)
Convert a dollar amount to cents (smallest currency unit)
The currency's minor unit comes from ISO 4217 through
minorUnitExponentin payments-core, matched in any case. A code outsideCurrencyCodegets its own multiplier (1000 forKWD, 1 forKRW).