0
Hello,
I have the following code to remove the colon and comma:
$valor = str_replace("." , "" , $valor );
$valor = str_replace("," , "" , $valor);
There is how to do this in a single code, without first doing one thing after another?
I searched and couldn’t find a solution to also remove the last two zeros.
Example: 300.000,00 Upshot: 300000
If the decimals are non-zero, you will still throw them away without rounding?
– Marco Aurélio Deleu
There will be no values other than zero, as they are real estate values.
– Gladison Neuza Perosini
to remove the semicolon, if I am not mistaken str_replace accepts arrays in the input, then it would be "str_replace([".", ","] , ["", ""] , $value );", I believe it would summarize in a line the removal of these characters.
– Ruggi
@Ruggi this code is in error.
– Gladison Neuza Perosini
You’re Right @Gladisonneuzaperosini, corrected.
– Ruggi
The error disappears, but when I run it gives error. It shows the following: Parse error: syntax error, Unexpected '[', expecting ')'
– Gladison Neuza Perosini
How do I remove the last two zeros?
– Gladison Neuza Perosini
The code in the Ruggi comment uses array alias, which is available from php 5.5. To make it compatible, use
str_replace(array('.', ','), '', $valor);
– Daniel Omine
In the title it says "white space". However, "white space" is different from "empty". I think you want to remove by switching to empty.
– Daniel Omine
actually @daniel-Omine is right, use what Daniel said to replace the score, then remove the last two zeroes, like this: $value = substr($value, 0, -2);
– Ruggi
I executed the code without errors, it was like this: $value = "300.000,00"; echo $value." </br>"; $value = str_replace(Array(",", "."), "", $value); echo $value. " </br>"; $value = substr($value, 0, -2 ); echo $value;
– Ruggi
@Ruggi I use in mysql the float field for coins, that’s correct?
– Gladison Neuza Perosini
@Ruggi whenever I record at the bank he eliminates a few zeros. Like, if I record 300,000 it stores only 300. I’ve lost track of what might be going on.
– Gladison Neuza Perosini
my, so when you write float type in mysql, its decimal separation should be with ".". then I advise you not to take the last two... and add the point in the correct location, you saw the post that marked that are duplicated the answers? tried to record in the bank that way?
– Ruggi