[英]Round Up Number Integer in Sql Query
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这是返回 918800
the return is correct 918,800返回正确 918,800
but in case @number = 918800 it will change into 918900.但如果@number = 918800,它会变成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它返回 918800,但如果我使用
SELECT ROUND(918740 , -2) AS RoundValue;
it return 918700, while i need is always round to up so the result i need is 918000它返回 918700,而我需要的总是向上取整,所以我需要的结果是 918000
if you re using any of Oracle, MySQL, and PostgreSQL, you can use ROUND()
function.如果您使用的是 Oracle、MySQL 和 PostgreSQL 中的任何一个,则可以使用
ROUND()
函数。
like this像这样
SELECT ROUND(918750 , -2)选择回合(918750 , -2)
this query will produce 918800 result -2
means the last two digits are rounded up.此查询将产生 918800 结果
-2
表示最后两位数字四舍五入。
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;
Try this one试试这个
DECLARE @Number INT = 435667
SELECT CONVERT(INT, 100 * ROUND(@Number / 100.0, 0))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.