php - Zend_Currency value with cents instead of dollars -
i using zend_currency , store values in cents (opposed to dollars) due other parts of system work in cents. so, initialise , retrieve values zend_currency objects in cents, there way configure zend_currency way?
i aware divide 100 when retrieve value, don't know how compatible when/if need internationalize. ie. all currencies 100 "cent" units "dollar".
are currencies 100 "cent" units "dollar"?
no.
although do, there few have base of '5' or base of '1000' or no decimal @ all.
source: http://en.wikipedia.org/wiki/list_of_circulating_currencies
you should using zend currency store raw value , let conversions you.
// 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());
note: my_currency_exchange() dummy class i've created, looks this:
<?php class my_currency_exchange implements zend_currency_currencyinterface { public function getrate($from, $to) { if ($from !== "usd") { throw new exception ('we usd : ' . $from); } switch ($to) { case 'omr': // value xe.com of today return '2.59740'; } } }
output: float(100.5) float(261.0387)
Comments
Post a Comment