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.

  • #764207

    Hi PaulRaj,

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


    value= Math.Round(value);

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

    Blog :

  • #764208
    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

  • #764209
    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.
    Give respect to your work, Instead of trying to impress your boss.

    Blog :

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

    Thanks with

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

    So can you please provide any example code or link .

    Thanking You

  • #764225


    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
    Email Id :

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

  • #764228
    Yes Mr.Kumar you are right,

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

    Thanks with

  • #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);

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

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

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.