Skip to content
Advertisement

MySQL remove zeros from decimal part if the number is whole

I have a sales table with price column as decimal(8, 2) and I’m running the query below to get the total price

It’s working perfectly but my results are usually intergers so I end up with trailing zeros all the time. It’d be nice to just return the whole number if there is no decimal part

Advertisement

Answer

like akina said in his comment …

you can cast the sum result to UNSIGNED INTEGER

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement