Example #1
0
                $formatted .= ' ';
            }
            $formatted .= $this->_currency->__toString();
            if (isset($rules['html']) && $rules['html']) {
                $formatted .= '</span>';
            }
        }
        return $formatted;
    }
    public function __toString()
    {
        $unit = (string) floor(abs($this->_cents) / $this->_currency->subunitToUnit);
        $subunit = (string) floor(abs($this->_cents) % $this->_currency->subunitToUnit);
        if ($this->_currency->decimalPlaces() == 0) {
            if ($this->_cents < 0) {
                return "-{$unit}";
            } else {
                return $unit;
            }
        }
        $subunit = str_repeat("0", $this->_currency->decimalPlaces()) . $subunit;
        $subunit = substr($subunit, -1 * $this->_currency->decimalPlaces());
        if ($this->_cents < 0) {
            return '-' . $unit . $this->decimalMark() . $subunit;
        } else {
            return $unit . $this->decimalMark() . $subunit;
        }
    }
}
Money::$defaultCurrency = new Currency('USD');