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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:59:55+00:00 2026-05-30T14:59:55+00:00

Why does this result in 0 and not 1? Math.Round(0.5, 0, MidpointRounding.AwayFromZero) Here’s an

  • 0

Why does this result in 0 and not 1?

Math.Round(0.5, 0, MidpointRounding.AwayFromZero)

Here’s an example: http://ideone.com/ayMVO

  • 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-30T14:59:56+00:00Added an answer on May 30, 2026 at 2:59 pm

    Normally, with issues like that, it’s because the number cannot be represented exactly in IEEE754 – it’s most likely it’s being converted to 0.4999999999… or something like that which would round to zero.

    However, 0.5 (1/2) is exactly representable in IEEE754 so that’s not the case here.

    It’s possible that the compiler made a mistake in converting the text to a number but I would think that unlikely. In fact, when I compile and run the following in VC#2010:

    using System;
    namespace ConsoleApplication1 {
        class Program {
            static void Main (string[] args) {
                Console.WriteLine (Math.Round (0.5, 0, MidpointRounding.AwayFromZero));
            }
        }
    }
    

    I get the output of 1 as expected.

    So I don’t think your question is quite complete. Now it may be that your actual situation doesn’t use a hard-coded value of 0.5 but instead uses a variable which you believe to be 0.5.

    My answer to that would be that, while it may be close to 0.5 (certainly close enough that a simple WriteLine of it might output 0.5), it’s probably a touch below 0.5, which would cause my comments in the first paragraph above to once again kick in.


    Based on your link, it appears that Mono 2.8 may have a bug. I’d suggesting seeking support from the developers (or just raising a bug report) here.

    Actually, having tried it locally with gmcs 2.6.7, it’s definitely a bug. That exact code compiled okay but generates 0 rather than 1. A bug report has been raised, and I’ve added my own information to it.

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

Sidebar

Related Questions

Why does this: (new[]{1,2,3}).Cast<decimal>(); result in an InvalidCastException: Specified cast is not valid.
The following does not compile: int result = Math.random() + 1; error: possible loss
Why does this test program result in a java.lang.IllegalMonitorStateException ? public class test {
I have been using Math.Round(myNumber, MidpointRounding.ToEven) in C# to do my server-side rounding, however,
Not strong in math so here is my problem: I am using a progress
Possible Duplicates: In C#: Math.Round(2.5) result is 2 (instead of 3)! Are you kidding
This results in a JSON string that contains street_number - http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false long_name : 1600,
I'm using MS Sql 2005. Why does this give me the correct results (returns
Does this pattern: setTimeout(function(){ // do stuff }, 0); Actually return control to the
Does this look like it should work? I'm wanting to generate directions from one

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.