Definition at line 8 of file Format.php.
◆ __construct()
- Parameters
-
\Magento\Framework\App\ScopeResolverInterface | $scopeResolver | |
ResolverInterface | $localeResolver | |
\Magento\Directory\Model\CurrencyFactory | $currencyFactory | |
Definition at line 30 of file Format.php.
35 $this->_scopeResolver = $scopeResolver;
36 $this->_localeResolver = $localeResolver;
◆ getNumber()
Returns the first found number from a string Parsing depends on given locale (grouping and decimal)
Examples for input: ' 2345.4356,1234' = 23455456.1234 '+23,3452.123' = 233452.123 ' 12343 ' = 12343 '-9456km' = -9456 '0' = 0 '2 054,10' = 2054.1 '2'054.52' = 2054.52 '2,46 GB' = 2.46
- Parameters
-
string | float | int | $value | |
- Returns
- float|null
Implements FormatInterface.
Definition at line 57 of file Format.php.
70 $separatorComa = strpos(
$value,
',');
71 $separatorDot = strpos(
$value,
'.');
73 if ($separatorComa !==
false && $separatorDot !==
false) {
74 if ($separatorComa > $separatorDot) {
79 }
elseif ($separatorComa !==
false) {
elseif(isset( $params[ 'redirect_parent']))
◆ getPriceFormat()
getPriceFormat |
( |
|
$localeCode = null , |
|
|
|
$currencyCode = null |
|
) |
| |
Returns an array with price formatting info
- Parameters
-
- Returns
- array
Definition at line 93 of file Format.php.
95 $localeCode = $localeCode ?: $this->_localeResolver->getLocale();
97 $currency = $this->currencyFactory->create()->load($currencyCode);
99 $currency = $this->_scopeResolver->getScope()->getCurrentCurrency();
102 $formatter = new \NumberFormatter(
103 $localeCode .
'@currency=' . $currency->getCode(),
104 \NumberFormatter::CURRENCY
106 $format = $formatter->getPattern();
107 $decimalSymbol = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
108 $groupSymbol = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
111 if (
$pos !==
false) {
116 $decimalPoint = strpos(
$format,
'.');
117 if ($decimalPoint !==
false) {
120 $decimalPoint = strlen(
$format);
122 $requiredPrecision = $totalPrecision;
123 $t = substr(
$format, $decimalPoint);
124 $pos = strpos($t,
'#');
125 if (
$pos !==
false) {
126 $requiredPrecision = strlen($t) -
$pos - $totalPrecision;
129 if (strrpos(
$format,
',') !==
false) {
137 'pattern' => $currency->getOutputFormat(),
138 'precision' => $totalPrecision,
139 'requiredPrecision' => $requiredPrecision,
140 'decimalSymbol' => $decimalSymbol,
141 'groupSymbol' => $groupSymbol,
143 'integerRequired' => $totalPrecision == 0,
◆ $_localeResolver
◆ $_scopeResolver
◆ $currencyFactory
The documentation for this class was generated from the following file: