currency format php code example
Example 1: php number format
$num = 12345.6789;
echo number_format($num, 2, '.', '')
echo number_format($num, 3, ',', '.')
Example 2: format php currency
<?php
$number = 1234.56;
$english_format_number = number_format($number);
$nombre_format_francais = number_format($number, 2, ',', ' ');
$number = 1234.5678;
$english_format_number = number_format($number, 2, '.', '');
Example 3: php money_format currency symbol
<?php
$number = 1234.56;
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%.2n', $number) . "\n";
$number = -1234.5672;
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
echo money_format('%=*(#10.2n', $number) . "\n";
setlocale(LC_MONETARY, 'de_DE');
echo money_format('%=*^-14#8.2i', 1234.56) . "\n";
setlocale(LC_MONETARY, 'en_GB');
$fmt = 'The final value is %i (after a 10%% discount)';
echo money_format($fmt, 1234.56) . "\n";
?>
Example 4: number format to float php
$num = '1,200,998.255';
########## FOR FLOAT VALUES ###########################
echo filter_var($num, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
#output : 1200998.255
########## FOR INTEGER VALUES ###########################
echo filter_var($num, FILTER_SANITIZE_NUMBER_INT);
#output : 1200998