0
I have three values that are being passed via POST to be recorded in the database, I try to record the data but it records with wrong values. The data is like this:
"valor_liquido": "R$1.000,00",
"valor_bruto": "R$1.000,00",
"valor_desconto": "R$0,00"
In the database they are recorded as 1.00,1.00 and 0.00
I used str_replace to remove the comma, but it didn’t work.
$estoque->valorbruto = str_replace(',','.',substr($v1,2));
What is the field type in the table? Decimal (9.2) for example?
– Miguel
But why not use the float field of the database, to record right?
– Sr. André Baill
The fields are decimal(13,2)
– Guilherme Costa
Float would look better?
– Guilherme Costa
your str_replace is not removing the miler separator... this is causing the problem.
– user2385
Solved. Vlw.
– Guilherme Costa
Float is not suitable for storing monetary values, see that answer and Best kind of data to work with money?
– rray
I’ll read this @rray always used the float, I think I’m wrong rsrsrrs thank you!
– Sr. André Baill