| @@ 61-68 (lines=8) @@ | ||
| 58 | * @param string $currencyCode |
|
| 59 | * @return string |
|
| 60 | */ |
|
| 61 | public function format($value, $currencyCode) |
|
| 62 | { |
|
| 63 | $currency = $this->get($currencyCode); |
|
| 64 | $format = $this->formatData->get(null); |
|
| 65 | $formatter = new NumberFormatter($format, NumberFormatter::CURRENCY); |
|
| 66 | ||
| 67 | return $formatter->formatCurrency($value, $currency); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Format an value for the given currency in accounting |
|
| @@ 78-85 (lines=8) @@ | ||
| 75 | * @param string $currencyCode |
|
| 76 | * @return string |
|
| 77 | */ |
|
| 78 | public function formatAccounting($value, $currencyCode) |
|
| 79 | { |
|
| 80 | $currency = $this->get($currencyCode); |
|
| 81 | $format = $this->formatData->get(null); |
|
| 82 | $formatter = new NumberFormatter($format, NumberFormatter::CURRENCY_ACCOUNTING); |
|
| 83 | ||
| 84 | return $formatter->formatCurrency($value, $currency); |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * Parse a localized value into native PHP format. |
|
| @@ 94-101 (lines=8) @@ | ||
| 91 | * @param string $currencyCode |
|
| 92 | * @return int|float |
|
| 93 | */ |
|
| 94 | public function parse($value, $currencyCode) |
|
| 95 | { |
|
| 96 | $currency = $this->get($currencyCode); |
|
| 97 | $format = $this->formatData->get(null); |
|
| 98 | $formatter = new NumberFormatter($format, NumberFormatter::CURRENCY); |
|
| 99 | ||
| 100 | return $formatter->parseCurrency($value, $currency); |
|
| 101 | } |
|
| 102 | ||
| 103 | /** |
|
| 104 | * Set the default locale. |
|
| @@ 60-69 (lines=10) @@ | ||
| 57 | * @param string|int|float $value |
|
| 58 | * @return int|float |
|
| 59 | */ |
|
| 60 | public function parse($value) |
|
| 61 | { |
|
| 62 | $format = $this->get(null); |
|
| 63 | $formatter = new NumberFormatter($format); |
|
| 64 | ||
| 65 | // At time of writing, commerceguys/intl has number parsing still coupled to a currency. Parsing does |
|
| 66 | // succeed however,even though a value is provided without any currency. So let's just pass in |
|
| 67 | // a very rare currency to avoid unwanted formatting behavior. Sorry Cape Verdean Escudo! |
|
| 68 | return $formatter->parseCurrency($value, $currency = currency()->get('CVE')); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * Get a localized entry. |
|