Can Can - 7 months ago 24
SQL Question

mysql decimal round

I'm new to mysql and need some basic things.

I need to round the decimals like :

21,4758 should be 21,48

0,2250 should be 0,22

23,0850 should be 23,08

22,9950 should be 22,99

I tried lots of thing but couldn't make it.

Thanks.

Answer
DECLARE @old decimal(38, 10)
DECLARE @p decimal(38, 10)
SET @p = 21.4758

SET @p = @p * 100
SET @p = @p - 0.01
SET @p = ROUND(@p, 0)
SET @p = @p / 100.0
SELECT @p
Comments