I have encountered occasion where I have to change database column ‘price’ ‘s data type from string to decimal. Problem is in the database there are some incorrect existing values like ‘120.45.32’ this shold corrected into ‘12045.32’. I have tried, CAST to decimal but it gives ‘120.00’. How can I resolve this in the migration file?
I have tried CAST(price as DECIMAL (10,2)). Migration works but all existing decimal values replace to ‘.00’ like 120.45 -> 120.00
2
Answers
Like Barmar said, you need to remove all first dots.
fiddle
first Clean up the incorrect data
then Convert to a DECIMAL type