Always round minor units to an integer

This commit is contained in:
Peter Smit
2025-09-13 11:41:33 +02:00
parent 05a793ee39
commit c49d0ea220

View File

@@ -99,10 +99,10 @@ export function amountAsDecimal(
* - €1.5 = 150 "minor units" of euros (cents) * - €1.5 = 150 "minor units" of euros (cents)
* - JPY 1000 = 1000 "minor units" of yen (the yen does not have minor units in practice) * - JPY 1000 = 1000 "minor units" of yen (the yen does not have minor units in practice)
* *
* @param amount The amount in decimal major units * @param amount The amount in decimal major units (always an integer)
*/ */
export function amountAsMinorUnits(amount: number, currency: Currency) { export function amountAsMinorUnits(amount: number, currency: Currency) {
return amount * 10 ** currency.decimal_digits return Math.round(amount * 10 ** currency.decimal_digits)
} }
/** /**