Every amount you send to VNSwitch, and every amount VNSwitch returns, is an integer in the currency’s minor unit (the smallest unit of that currency). This applies to payment amounts, capture amounts, refunds and payouts alike. Dispute objects are the one exception in format, not in meaning: their amount is a string holding the minor-unit integer (for example "150000"), so parse it as an integer.

Minor units and VND

The number of minor units in one major unit depends on the currency:

CurrencyDecimal placesamount you sendMeans
VND0150000150,000 VND
USD2105010.50 USD
KWD315001.500 KWD

VND has no minor unit. The amount is the number of dong: amount: 150000 with currency: "VND" is 150,000 VND. Do not multiply VND amounts by 100.

A common bug is to treat every currency as having two decimal places. For VND that charges the customer 100 times too much: 15000000 is 15,000,000 VND, not 150,000 VND. Always look up the decimal places of the currency before you convert.

The amount field is an integer. A value with a fractional part, such as 150000.5, is not a valid amount and the request is rejected (see Errors).

Currency codes

The currency field takes a three-letter ISO 4217 code in uppercase, for example "VND" or "USD". Which currencies you can actually charge depends on the payment providers enabled for your account.

VNSwitch uses these decimal places:

Decimal placesCurrencies
0BIF, CLP, DJF, GNF, IRR, JPY, KMF, KRW, MGA, PYG, RWF, UGX, VND, VUV, XAF, XOF, XPF
3BHD, IQD, JOD, KWD, LYD, OMR, TND
4CLF
2All other supported currencies (for example USD, EUR, SGD, THB)

Convert amounts safely

The examples in the code column convert between a decimal string (what a person types or what your order system stores, for example "10.50") and the integer that VNSwitch expects, and back again for display.

  • Never use floating-point numbers for money. 10.50 * 100 in binary floating point can give 1049.9999999999998. Work with integers, a decimal string, or an exact decimal type (Decimal in Python, BigDecimal in Java).
  • Reject values with too many decimal places instead of rounding them silently. "10.505" is not a valid USD amount, and "150000.5" is not a valid VND amount.
  • Store the integer and the currency together. An amount without its currency is ambiguous: 150000 is 150,000 VND but 1,500.00 USD.
  • Keep amounts in minor units end to end. Convert only at the edges: when a person enters an amount and when you show one.