In my first attempt i simply used CAST to convert text to decimal, something like:
ORDER BY CAST( price as decimal(10,2))
Unfortunately, mysql doesn’t like commas at all: it just “cuts” the number whenever it finds one. To get my queryset ordered properly i had to get rid of the commas, so i used replace:
ORDER BY CAST( replace(price,’,’,’.’) as decimal(10,2))
This tip is also useful when you have decimals with commas you want to display with points and vice versa.
Nessun commento:
Posta un commento