I have this
$example = "1234567"
$subtotal = number_format($example, 2, '.', '');
the return of $subtotal is "1234567.00"
how to modify the definition of $subtotal, make it like this "1,234,567.00"
The character used as the thousands separatorIn the United States, this character is a comma (,). In Germany, it is a period (.). Thus one thousand and twenty-five is displayed as 1,025 in the United States and 1.025 in Germany. In Sweden, the thousands separator is a space.
Below will output 1,234,567.00
$example = "1234567";
$subtotal = number_format($example, 2, '.', ',');
echo $subtotal;
Syntax
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
But I advise you to use money_format which will formats a number as a currency string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With