Convert money between major and minor units correctly
The Currency Minor Unit Converter turns a human-readable amount like $19.99 into the integer 1999 that payment APIs expect, and back again. It uses the official ISO 4217 minor-unit exponent for each currency, so it stays correct for zero-decimal currencies like the Japanese yen and three-decimal currencies like the Bahraini dinar.
How it works
ISO 4217 assigns each currency an exponent — the number of decimal digits in its minor unit. The conversion is a simple power of ten:
minor = round(major × 10^exponent)
major = minor ÷ 10^exponent
- USD has exponent 2:
19.99 × 100 = 1999cents. - JPY has exponent 0:
2000 × 1 = 2000— major and minor are the same. - BHD has exponent 3:
1.999 × 1000 = 1999fils.
When converting major to minor, the tool rounds to the nearest integer. This matters because 19.99 * 100 in floating-point arithmetic can evaluate to 1998.9999999999998; naive truncation would give 1998 instead of the correct 1999.
Example
Sending a charge of 1.5 BHD to a payment processor requires 1500, not 150. Selecting BHD (exponent 3) and converting major to minor gives exactly that. Conversely, refunding 1500 minor BHD divides by 1000 to show 1.500 BHD.
Notes
Always derive the multiplier from the ISO 4217 exponent rather than hard-coding ×100. A fixed multiplier silently fails for the dozen-plus zero-decimal and three-decimal currencies, causing 100x overcharges or undercharges that are easy to miss in testing.