moneyphp库:从RUB到AZN转换总是返回«zero»

时间:2017-02-05 18:34:13

标签: php currency

我正在使用https://github.com/moneyphp/money库。

这是一个简单的例子:

$ISO    = new \Money\Currencies\ISOCurrencies();
$Parser = new \Money\Parser\DecimalMoneyParser($ISO);

$Exchange = new \Money\Exchange\ReversedCurrenciesExchange(new \Money\Exchange\FixedExchange([
        'AZN' => [
                'RUB' => 30.5867
            ],
    ]));

$Converter = new \Money\Converter($ISO, $Exchange);

$RUB = $Parser->parse('1000.10', 'RUB');
$AZN = $Converter->convert($RUB, new \Money\Currency('AZN'));

echo '<pre>
1000.10 RUB = '.$RUB->getAmount().' RUB PARSED
1000.10 RUB = '.$AZN->getAmount().' AZN
</pre>';

将返回:

1000.10 RUB = 100010 RUB PARSED
1000.10 RUB = 0 AZN

同样是FixedExchange

$ISO    = new \Money\Currencies\ISOCurrencies();
$Parser = new \Money\Parser\DecimalMoneyParser($ISO);

$Exchange = new \Money\Exchange\FixedExchange([
        'RUB' => [
                'AZN' => 0.03
            ],
    ]);

$Converter = new \Money\Converter($ISO, $Exchange);

$RUB = $Parser->parse('1000.10', 'RUB');
$AZN = $Converter->convert($RUB, new \Money\Currency('AZN'));

echo '<pre>
1000.10 RUB = '.$RUB->getAmount().' RUB PARSED
1000.10 RUB = '.$AZN->getAmount().' AZN
</pre>';

将返回:

1000.10 RUB = 100010 RUB PARSED
1000.10 RUB = 0 AZN

可是:

$Exchange = new \Money\Exchange\FixedExchange([
        'RUB' => [
                'AZN' => 3.00
            ],
    ]);

将返回:

1000.10 RUB = 100010 RUB PARSED
1000.10 RUB = 300030 AZN

和...

$Exchange = new \Money\Exchange\FixedExchange([
        'RUB' => [
                'AZN' => 3.01
            ],
    ]);

将返回:

1000.10 RUB = 100010 RUB PARSED
1000.10 RUB = 0 AZN

怎么了?错误在哪里?

0 个答案:

没有答案