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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:51:33+00:00 2026-06-01T19:51:33+00:00

I am looking for a way to round to the nearest dollar with the

  • 0

I am looking for a way to round to the nearest dollar with the following stipulations:
(If wholenumber.50 and above round up to the next whole number)
(If wholenumber.49 and below round down to the current whole number)

I have tried:

Math.Round(wholenumber.xx, MidpointRounding.ToEven);

This doesn’t always round how I want for instance 1.5 = 2 and 2.5 = 2 as it rounds to nearest even number.

I have also tried:

Math.Round(wholenumber.xx, MidpointRounding.AwayFromZero);

This always rounds up to the higher whole number.

Is there any built in functionality for what I am trying to do or will I need to write my own custom method to check the number and do floor or ceil depending?

  • 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-01T19:51:34+00:00Added an answer on June 1, 2026 at 7:51 pm

    First off, I note that you should always use decimal for this task; never use double. If you are using double, stop what you are doing right now and fix your program so that you stop using a type designed for physics problems and start using a type designed for money problems to solve your money problem.

    Second, you are simply wrong when you say

    This always rounds up to the higher whole number.

    It does not. It rounds to the nearest whole number, and if there is no nearest whole number because you are at a midpoint, then it chooses the whole number that is farther from zero.

    Try it, if you don’t believe me:

    using System;
    class P
    {
      static void Main()
      {
        decimal buckFifty = 1.50m;
        decimal buckFortyNine = 1.49m;
        Console.WriteLine(Math.Round(buckFortyNine, MidpointRounding.AwayFromZero));
        Console.WriteLine(Math.Round(buckFifty, MidpointRounding.AwayFromZero));
        Console.WriteLine(Math.Round(-buckFortyNine, MidpointRounding.AwayFromZero));
        Console.WriteLine(Math.Round(-buckFifty, MidpointRounding.AwayFromZero));
      }
    }
    

    results are

    1
    2
    -1
    -2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to round up a number to the next closest
I'm looking to find a way to round up to the nearest 500.I've been
Is there any way to round a float to the nearest decimal place in
I'm looking for a fail-safe way to round-trip between a Flash swf file and
Consider the following code that is intended to round numbers to the nearest one-hundredth
Whats the best way to round in VBA Access? My current method utilizes the
I'm looking for way to create list view as like in IOS with pinned
I'm looking a way to enable IP logging with log4net in ASP.NET. I found
I'm looking for way to write Javascript programs / scripts on desktop, not inside
I'm looking a way to build conditional assignments in bash: In Java it looks

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.