Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:19:18+00:00 2026-05-31T18:19:18+00:00

Possible Duplicate: c# – How do I round a decimal value to 2 decimal

  • 0

Possible Duplicate:
c# – How do I round a decimal value to 2 decimal places (for output on a page)

how to return decimal with long rest after the point like that:

3.786444499963

to this:

3.787

its not just cut the points it also round the rest of the number

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:19:19+00:00Added an answer on May 31, 2026 at 6:19 pm

    But the generally accepted rounding of 3.786444499963 to three decimal places is 3.786. Why do you think otherwise?

    Thus:

    var round = Math.Round(3.786444499963m, 3, MidpointRounding.AwayFromZero);
    Console.WriteLine(round == 3.786m); // prints true
    

    If you want it to ALWAYS round up:

    var round = Math.Round(3.786444499963m + 0.0005m, 3);
    Console.WriteLine(round == 3.787m); // prints true
    

    Do you see what I did there? I added 0.0005m to the input before using Math.Round. In general, to round x to n decimal places,

    var round = Math.Round(x + 5m * Convert.ToDecimal(Math.Pow(10, -n - 1)), n);
    

    Or, perhaps, to avoid the ugly double/decimal conversion:

    int k = 1;
    decimal value = 5m;
    while(k <= n + 1) { value /= 10m; k++; }
    var round = Math.Round(x + value, n);
    

    There’s an edge case you need to be aware of. What happens to 3.786? Should it be rounded up to 3.787 or remain at 3.786? You haven’t specified what you want exactly, so I’ll leave this edge case to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why do I see a double variable initialized to some value like
Possible Duplicate: How to minify php page html output? Any reason not to strip
Possible Duplicate: array_splice() for associative arrays How to add an array value to the
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: How an uninitialised variable gets a garbage value? So when an undefined
Possible Duplicate: Unload a module in Python After importing Numpy, lets say I want
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: C# okay with comparing value types to null Consider the following code
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.