epay_money (erlang_pay v0.3.2)
View Source多币种金额换算 / ISO 4217 minor-unit conversion
金额货币铁律:最小单位与货币码同存,小数位数(exponent)随币种而变, 不可假定恒为 2 位(×100)。USD/EUR/CNY=2,JPY/KRW=0,BHD/KWD=3。
为杜绝浮点误差,主单位一律以 binary 字符串传入/返回(如 <<"12.34">>),
内部全程整数运算。最小单位为 integer(如 1234 表示 12.34 USD)。
Summary
Functions
查币种小数位数。未知币种返回明确错误。
最小单位整数 → 主单位字符串。如 to_major(1234, <<"USD">>) = {ok, <<"12.34">>}。
主单位字符串 → 最小单位整数。如 to_minor(<<"12.34">>, <<"USD">>) = {ok, 1234}。
Types
-type currency() :: binary().
Functions
-spec exponent(currency()) -> {ok, non_neg_integer()} | {error, {unsupported_currency, currency()}}.
查币种小数位数。未知币种返回明确错误。
最小单位整数 → 主单位字符串。如 to_major(1234, <<"USD">>) = {ok, <<"12.34">>}。
主单位字符串 → 最小单位整数。如 to_minor(<<"12.34">>, <<"USD">>) = {ok, 1234}。