3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $formatter = new \NumberFormatter('de_CH', \NumberFormatter::CURRENCY); $format = $formatter->getPattern(); #$decimalSymbol = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); #$groupSymbol = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL); #echo $format . ' ' . $decimalSymbol . ' ' . $groupSymbol; $r = form($format); var_dump($r); function form($format) { $pos = strpos($format, ';'); if ($pos !== false) { $format = substr($format, 0, $pos); } $format = preg_replace("/[^0\#\.,]/", "", $format); $totalPrecision = 0; $decimalPoint = strpos($format, '.'); if ($decimalPoint !== false) { $totalPrecision = strlen($format) - (strrpos($format, '.') + 1); } else { $decimalPoint = strlen($format); } $requiredPrecision = $totalPrecision; $t = substr($format, $decimalPoint); $pos = strpos($t, '#'); if ($pos !== false) { $requiredPrecision = strlen($t) - $pos - $totalPrecision; } if (strrpos($format, ',') !== false) { $group = $decimalPoint - strrpos($format, ',') - 1; } else { $group = strrpos($format, '.'); } $integerRequired = strpos($format, '.') - strpos($format, '0'); return [ 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'group' => $group, 'integerRequired' => $integerRequired ]; }
based on kvlYn
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
array(4) { ["precision"]=> int(2) ["requiredPrecision"]=> int(2) ["group"]=> int(3) ["integerRequired"]=> int(1) }