# 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

You must Sign In to post a response.

- Category: ASP.NET
# 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 - #764207

Hi PaulRaj,

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

Ex:

value= Math.Round(value);*--------------------------------------------------------------------------------*

Give respect to your work, Instead of trying to impress your boss.

N@veen

Blog : http://naveens-dotnet.blogspot.in/ - #764208Hmm 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 - #764209Yes, 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.
*--------------------------------------------------------------------------------*

Give respect to your work, Instead of trying to impress your boss.

N@veen

Blog : http://naveens-dotnet.blogspot.in/ - #764212Oh ok mr.Naveen ,

Thanks a lot for your guide & Cooperation in every time with me & ALL

Thanks with

Paul.S - #764223I cant able to get exact output of Roundof a value Mr.naveen.

So can you please provide any example code or link .

Thanking You

Paul.S - #764225

Hi

Paul

In sql server using round function try this

Select round(121.25,-2)

--Answer 100.00

Select round(121.25,-1)

--Answer 120.00*Name : Dotnet Developer-2015*

'Not by might nor by power, but by my Spirit,' says the LORD Almighty. - #764228Yes Mr.Kumar you are right,

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

Thanks with

Paul.S - #764230

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]

Return to Return to Discussion Forum