SQL Server 'ROUND' vs C# 'Math.Round' -


i have following sql server statement, want convert c#. know there called math.round in c#. have tried c# returns same results c# returns int back. details please check test & results below:

sql server

select round(sum(somevalue) / 60,0)   

c#

var alpha = math.round(somevalue / 60, 0); 

tests & result

select round(150.75, 0) -- result = 151.00  var alpha = math.round(150.75, 0); // result = 151 

can please suggest me why not putting .00 in end. in real values there difference. looking ro replace sql c#.

thanks

as per table on msdn here sql server's round() return decimal output decimal input.

the overloads of math.round return either decimal or double, depending on input type.

the reason why aren't seeing .00 therefore must result of formatting applying result.

(speculative, default formatting on string.format or debug.writeline may internally using technique such this retrieve number of decimal places , provide default presentation), e.g.

int count = bitconverter.getbytes(decimal.getbits(math.round(150.75m, 0))[3])[2]; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -