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 8864089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:09:02+00:00 2026-06-14T16:09:02+00:00

I have tried using Math.Round and MidpointRounding . This does not appear to do

  • 0

I have tried using Math.Round and MidpointRounding. This does not appear to do what I need.

Example:

52.34567 rounded to 2 decimals UP   = 52.35
 1.183   rounded to 2 decimals DOWN =  1.18

Do I need to write a custom function?

Sometimes I need a number like 23.567 to round DOWN to 23.56.
In this scenario…

Math.Round(dec, 2, MidpointRounding.AwayFromZero) gives 23.57
Math.Round(dec, 2, MidpointRounding.ToEven) gives 23.57

Decimals up to 9 decimal places could come out and need to be rounded to 1, 2, 3 or even 4 decimal places.

  • 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-06-14T16:09:04+00:00Added an answer on June 14, 2026 at 4:09 pm

    Try using decimal.Round():

    decimal.Round(x, 2)
    

    Where x is your value and 2 is the number of decimals you wish to keep.

    You can also specify whether .5 rounds up or down by passing third parameter:

    decimal.Round(x, 2, MidpointRounding.AwayFromZero);
    

    EDIT:

    In light of the new requirement (i.e. that numbers are sometimes rounded down despite being greater than “halfway” to the next interval), you can try:

    var pow = Math.Pow(10, numDigits);
    var truncated = Math.Truncate(x*pow) / pow;
    

    Truncate() lops off the non-integer portion of the decimal. Note that numDigits above should be how many digits you want to KEEP, not the total number of decimals, etc.

    Finally, if you want to force a round up (truncation really is a forced round-down), you would just add 1 to the result of the Truncate() call before dividing again.

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

Sidebar

Related Questions

I have tried using the accordion plugin, but it does not work, and I
I have tried using a stemmer but the words it produces are just not
I have tried using the code below but it only display results in Chrome
I have tried using date(m/d/Y, strtotime(04-05-2012)) but I will get 05/04/2012 or on some
I have a problem decoding HTML entities. I have tried using both System.Net.WebUtility.HtmlDecode() and
How can I avoid NullPointerExceptions ? I have tried using try-catch blocks but that
Is it possible to input hardcoded values for a rallymultiobjectpicker? I have tried using
I am trying to programatically unzip a zipped file. I have tried using the
Hi I want to create a JSON array. I have tried using: JSONArray jArray
We have tried it using an orm mapper tool, but it opens en closes

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.