June 29, 2015 at 12:46 am
sayedkhalid99 (6/28/2015)
how to round the nearest value after round of decimal and return integer. thanks.declare @data decimal(18,2)
set @data = 5.55
-- output
select '5'
set @data = 5.58
-- output
select '6'
Quick suggestion, use the ROUND function to round the decimal and the CONVERT to return an Integer.
😎
USE tempdb;
GO
SET NOCOUNT ON;
declare @data decimal(18,2) = 5.55;
SELECT CONVERT(INT,ROUND(@data,0,0),0);
June 29, 2015 at 9:06 am
sayedkhalid99 (6/28/2015)
how to round the nearest value after round of decimal and return integer. thanks.declare @data decimal(18,2)
set @data = 5.55
-- output
select '5'
set @data = 5.58
-- output
select '6'
I'm at a loss as to what rule you would use for rounding to get a value of 5 from 5.55, but a value of 6 from 5.58 ...
The ROUND() function will take both of those values to 6 when rounded to zero decimal places. It would require a
value of less than 5.5 to get a roundiing down to 5. FYI...
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply