Just forgot to remove the stitch.
It should be like this
$estoque->valorbruto = str_replace('.', '', str_replace(',','.',substr($v1,2)));
The logic here is to first convert comma per point and then remove any other existing points.
Unit of thousands
In computation there are no markers for thousand units. This markup is merely visual. The point represents decimal, so you get unexpected results like the one presented in the question.
Tip: decimal places
Another tip, think carefully if you really want to maintain monetary value with only 2 decimal places. In a division you can have . 333333333, for example.
It would be "eating" 3333333, are 7 houses. In a system with many transactions this is a huge hole in the accounts. But it’s not mandatory because it varies with each business Logic. Just be aware in modeling a business model that requires greater precision.
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