21 private $fractionDigits;
28 $this->fractionDigits = $fractionDigits;
34 public function parse($money, $forceCurrency =
null)
36 if (is_string($money) ===
false) {
44 if ($forceCurrency ===
null) {
52 $currency = $forceCurrency;
53 if (!$currency instanceof
Currency) {
54 @trigger_error(
'Passing a currency as string is deprecated since 3.1 and will be removed in 4.0. Please pass a '.Currency::class.
' instance instead.', E_USER_DEPRECATED);
59 $decimalSeparator = strpos($decimal,
'.');
61 if (
false !== $decimalSeparator) {
62 $decimal = rtrim($decimal,
'0');
63 $lengthDecimal = strlen($decimal);
64 $decimal = str_replace(
'.',
'', $decimal);
65 $decimal .= str_pad(
'', ($lengthDecimal - $decimalSeparator - $this->fractionDigits - 1) * -1,
'0');
67 $decimal .= str_pad(
'', $this->fractionDigits,
'0');
70 if (substr($decimal, 0, 1) ===
'-') {
71 $decimal =
'-'.ltrim(substr($decimal, 1),
'0');
73 $decimal = ltrim($decimal,
'0');
76 if (
'' === $decimal) {
80 return new Money($decimal, $currency);