Mahdi Bagheri
Mahdi Bagheri

Reputation: 23

round down and up in sql

I want to know how to round up and down between in a range example:

57272.726 ---> 57272.730
57272.724--> 57272.720

Upvotes: 1

Views: 2136

Answers (4)

codeX
codeX

Reputation: 5398

The following query may help you getting the desirable result.

Select ROUND( number, decimal_places [, operation ] )

SELECT round(57272.724, 2);

It gives 57272.72 as answer. It gets round down because last decimal digit is 4 which is in the range 0.1 to 0.4

SELECT round(57272.726, 2);

It gives 57272.73 as answer. It gets round up because last decimal digit is 6 which is in the range 0.5 to 0.9

Upvotes: 0

harish
harish

Reputation: 11

select round(57272.726);

Output : 57273

Syntax:

Select round(X,D);

X: The argument or the number you want to round

D: The no.of Decimal places you want to round(If you have not specified it, it is taken as zero)

Hope this Helps

Upvotes: 1

Vinoth Raj
Vinoth Raj

Reputation: 296

Use this code:

Round Up:-

declare @value decimal(10,2)
set @value=57272.726

SELECT CAST(ROUND(@value, 2) AS NUMERIC(12,3)) As RoundUpValues

Round Down:-

declare @value decimal(10,2)
set @value=57272.724

SELECT CAST(ROUND(@value, 2) AS NUMERIC(12,3)) As RoundDownValues

Upvotes: 0

Ilyes
Ilyes

Reputation: 14928

Try this :

SELECT ROUND(57272.726 , 2);

Return : 57272.730.

SELECT ROUND(57272.724 , 2);

return : 57272.720.

Upvotes: 0

Related Questions