すべての通貨は「ドル」に対して 100「セント」単位ですか?
いいえ。
ほとんどはそうですが、基数が「5」または基数が「1000」であるか、小数点以下がまったくないものもいくつかあります。
ソース: http://en.wikipedia.org/wiki/List_of_circulating_currencies
Zend Currency を使用して生の値を保存し、変換を行う必要があります。
// original money
$money = new Zend_Currency('US');
$money->setValue('100.50');
// conversion
$oman = new Zend_Currency('OM');
$oman->setService(new My_Currency_Exchange());
$oman->setValue($money->getValue(), $money->getShortName());
var_dump($money->getValue(), $oman->getValue());
注: My_Currency_Exchange() は私が作成したダミー クラスで、次のようになります。
<?php
class My_Currency_Exchange implements Zend_Currency_CurrencyInterface
{
public function getRate($from, $to)
{
if ($from !== "USD") {
throw new Exception ('We only do USD : ' . $from);
}
switch ($to) {
case 'OMR':
// value from xe.com as of today
return '2.59740';
}
}
}
出力:
float(100.5) float(261.0387)