I have this code to give $value
a number format:
$value=1000000.00;
number_format($value,2);
echo str_replace(",", "", $value)
But when I try to replace the comma, the decimals get removed. I want to print $value
as it originally was: 1000000.00
. How can I do that?
You have to assign the output of number_format
to the variable:
$value=1000000.00;
$value = number_format($value,2);
echo str_replace(",", "", $value);
Output:
1000000.00
You can also simply tell number_format
not to use a thousands separator:
$value = number_format($value,2,'.','');
echo $value;
Output:
1000000.00
Demo on 3v4l.org
You can tell number_format what it should use as decimal-point and thousands-seperator! No need for the str_replace:
$value = 1000000.00;
echo number_format($value, 2, ".", "");
// output:
// 1000000.00
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