• # How to Round of Input values using C#

Hi Developers,

Am creating a Cost Sheet in my Project. So i want to round of the values which is entered by the user.So help me to how i am done this task using c# Code.

Thanking you.

with
Paul.S

• Hi PaulRaj,

You can round it using Math.Round function, use that to round as you expected.

Ex:
`value= Math.Round(value);`

--------------------------------------------------------------------------------

N@veen
Blog : http://naveens-dotnet.blogspot.in/

• Hmm Thanks a lot Mr.Naveen.

if value is = 12.66
after this code
value= Math.Round(value);
it will be 13. Am right.

Thanking you,
with Paul.S

• Yes, obviously if the value is 12.51 then the result would be 13, if the value is 12.49 then the result would be 12.
--------------------------------------------------------------------------------

N@veen
Blog : http://naveens-dotnet.blogspot.in/

• Oh ok mr.Naveen ,
Thanks a lot for your guide & Cooperation in every time with me & ALL

Thanks with
Paul.S

• I cant able to get exact output of Roundof a value Mr.naveen.

Thanking You
Paul.S

• Hi
Paul

In sql server using round function try this

`Select round(121.25,-2)--Answer 100.00Select round(121.25,-1)--Answer 120.00`

Name : Dotnet Developer-2015
Email Id : kumaraspcode2009@gmail.com

'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

• Yes Mr.Kumar you are right,

But can you please provide any C# code as well.

Thanks with
Paul.S

• You can use Math.Round method, it rounds numbers to the nearest value. It receives the desired number of significant digits
see below sample
double before1 = 123.45;
double after1 = Math.Round(before1, 1,
MidpointRounding.AwayFromZero); // Rounds "up"
double after2 = Math.Round(before1, 1,
MidpointRounding.ToEven); // Rounds to even
double after3 = Math.Round(before1);

output
123.45
123.5 <-- MidpointRounding.AwayFromZero
123.4 <-- MidpointRounding.ToEven

Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]