ACs
ACs

Reputation: 1445

Mysql truncating decimals

I have a decimal type field im MySQL and I'd like to truncate it in a query to a specifiv number of decimals:

fields DDL:

<!-- language=sql -->
`discountprice` decimal(14,4) NOT NULL DEFAULT '0.0000',

If I select the value it displays with 4 decimals but if I truncate it to 2 decimals, then all the decimals are gone. Why?

This will output: 14000.0000

<!-- language=sql -->
SELECT ipr.discountprice AS 'nettoegysar'

While this is: 14000

<!-- language=sql -->
TRUNCATE(ipr.discountprice, 2) AS 'nettoegysar'

Upvotes: 0

Views: 388

Answers (1)

Rahul
Rahul

Reputation: 77876

What if you use ROUND() function instead like below which will round it to 2 decimal places.

SELECT ROUND(ipr.discountprice, 2) AS 'nettoegysar'

Upvotes: 0

Related Questions