Remove comma from number format without removing decimal point in PHP
Get the solution ↓↓↓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?
Answer
Solution:
You have to assign the output of to the variable:
$value=1000000.00;
$value = number_format($value,2);
echo str_replace(",", "", $value);
Output:
1000000.00
You can also simply tellnumber_format
not to use a thousands separator:
$value = number_format($value,2,'.','');
echo $value;
Output:
1000000.00
Answer
Solution:
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
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot add or update a child row: a foreign key constraint fails
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.