i have Query for round up for my store procedure like this
DECLARE @number int;
SET @number = 918750;
select @number (100 - @number % 100 )
this is return 918800
the return is correct 918,800
but in case @number = 918800 it will change into 918900.
and i want only 2 last digit is round up.
can i change it into single query only?
yes if i use
SELECT ROUND(918750 , -2) AS RoundValue;
it return 918800, but if i use
SELECT ROUND(918740 , -2) AS RoundValue;
it return 918700, while i need is always round to up so the result i need is 918000
CodePudding user response:
if you re using any of Oracle, MySQL, and PostgreSQL, you can use ROUND()
function.
like this
SELECT ROUND(918750 , -2)
this query will produce 918800 result
-2
means the last two digits are rounded up.
CodePudding user response:
Try this
DECLARE @number int;
SET @number = 918750;
// Solution 1
select @number -(@number % 100) iif(@number%100!=0,100,0);
//Solution 2
select ceiling(@number/100.00)*100;
CodePudding user response:
Try this one
DECLARE @Number INT = 435667
SELECT CONVERT(INT, 100 * ROUND(@Number / 100.0, 0))