As I explained in this question , I am using maskMoney
to generate a currency mask in multiple fields input
of type="text"
, except that when I perform arithmetic operations with the values obtained, and then I use number_format
in the output, it gives several types of formatting problems (does not include comma, etc.).
The solution I found on that topic was as follows:
$ultsalbase = $_POST["Tultsal"];
$ultsalbase2 = str_replace('.', '', $ultsalbase);
$ultsalbase3 = str_replace(',', '.', $ultsalbase2);
In this way, when the value enters the form in the format 1.000,00, the str_replace
transforms it to 1000.00. Then after doing the calculations, number_format
correctly returns the values in currency (1,000.00).
What happens is that because there are many fields, I'm thinking it might be wrong to have to create two new variables for each field, just to change the formatting.
Is not there a simpler solution for this?
I tried this:
$ultsalbase = $_POST["Tultsal"] . str_replace('.', '', $ultsalbase) . str_replace(',', '.', $ultsalbase);
But it did not work. Any ideas?