this class seems to be painful: it is not, formatting and parsing are highly customizable, but what you probably need is really simple:
if you want to localize a number use:
<?php
$a = new \NumberFormatter("it-IT", \NumberFormatter::DECIMAL);
echo $a->format(12345.12345) . "<br>"; $a->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$a->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 100); echo $a->format(12345.12345) . "<br>"; ?>
if you want to print money use:
<?php
$a = new \NumberFormatter("it-IT", \NumberFormatter::CURRENCY);
echo $a->format(12345.12345) . "<br>"; ?>
if you have money data stored as (for example) US dollars and you want to print them using the it-IT notation, you need to use
<?php
$a = new \NumberFormatter("it-IT", \NumberFormatter::CURRENCY);
echo $a->formatCurrency(12345, "USD") . "<br>"; ?>
another useful example about currency (how to obtain the currency name by a locale string):
<?php
$frontEndFormatter = new \NumberFormatter("it-IT", \NumberFormatter::CURRENCY);
$adminFormatter = new \NumberFormatter("en-US", \NumberFormatter::CURRENCY);
$symbol = $adminFormatter->getSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL); echo $frontEndFormatter->formatCurrency(12345.12345, $symbol) . "<br>";
?>