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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:48:17+00:00 2026-06-03T05:48:17+00:00

I know this has been discussed time and time again, but I can’t seem

  • 0

I know this has been discussed time and time again, but I can’t seem to get even the most simple example of a one-step division of doubles to result in the expected, unrounded outcome in C# – so I’m wondering if perhaps there’s i.e. some compiler flag or something else strange I’m not thinking of. Consider this example:

double v1 = 0.7;
double v2 = 0.025;
double result = v1 / v2;

When I break after the last line and examine it in the VS debugger, the value of “result” is 27.999999999999996. I’m aware that I can resolve it by changing to “decimal,” but that’s not possible in the case of the surrounding program. Is it not strange that two low-precision doubles like this can’t divide to the correct value of 28? Is the only solution really to Math.Round the result?

  • 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-03T05:48:18+00:00Added an answer on June 3, 2026 at 5:48 am

    Is it not strange that two low-precision doubles like this can’t divide to the correct value of 28?

    No, not really. Neither 0.7 nor 0.025 can be exactly represented in the double type. The exact values involved are:

    0.6999999999999999555910790149937383830547332763671875
    0.025000000000000001387778780781445675529539585113525390625
    

    Now are you surprised that the division doesn’t give exactly 28? Garbage in, garbage out…

    As you say, the right result to represent decimal numbers exactly is to use decimal. If the rest of your program is using the wrong type, that just means you need to work out which is higher: the cost of getting the wrong answer, or the cost of changing the whole program.

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

Sidebar

Related Questions

I know this has been discussed over and over again but I can't find
I know this has been discussed ad-nauseum but I just don't get some of
I know this topic has been discussed and killed over and over again, but
I know this has been discussed a lot of times but is there any
I know this topic has been discussed to death, but there is one thing
I know this is a question that has been discussed over and over, but
I know that this has been discussed lot of times. I just can't understand
I know this has been discussed earlier but I couldn't find a satisfactory answer.
I know this has been discussed ad nauseum...but I have an issue with the
I know this topic has been discussed before on Stack Overflow. But there are

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.