22 private $fractionDigits;
35 $this->fractionDigits = $fractionDigits;
36 $this->currencies = $currencies;
51 if (
'-' === $valueBase[0]) {
53 $valueBase = substr($valueBase, 1);
56 $subunit = $this->currencies->subunitFor($money->
getCurrency());
58 $valueLength = strlen($valueBase);
60 if ($valueLength > $subunit) {
61 $formatted = substr($valueBase, 0, $valueLength - $subunit);
65 $formatted .= substr($valueBase, $valueLength - $subunit);
68 $formatted =
'0.'.str_pad(
'', $subunit - $valueLength,
'0').$valueBase;
71 if ($this->fractionDigits === 0) {
72 $formatted = substr($formatted, 0, strpos($formatted,
'.'));
73 } elseif ($this->fractionDigits > $subunit) {
74 $formatted .= str_pad(
'', $this->fractionDigits - $subunit,
'0');
75 } elseif ($this->fractionDigits < $subunit) {
76 $lastDigit = strpos($formatted,
'.') + $this->fractionDigits + 1;
77 $formatted = substr($formatted, 0, $lastDigit);
82 if (
true === $negative) {
83 $formatted =
'-'.$formatted;