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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:34:49+00:00 2026-06-18T01:34:49+00:00

double c, d, e; double a = (c – d) / e; double b

  • 0
double c, d, e;
double a = (c - d) / e;
double b = Math.Floor(a);
Debug.WriteLine(a.ToString() + " " + b.ToString());

Code above outputs “3 2” at one configuration where all numbers are double. How is this possible? Is it because of fractional error resulting from double operations? However I think a.ToString() should give the whole number with its fractional part.

  • 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-18T01:34:50+00:00Added an answer on June 18, 2026 at 1:34 am

    It’s just a matter of what double.ToString() does. Here’s a short but complete program demonstrating the same thing:

    using System;
    
    public class Test
    {
        static void Main(string[] args)
        {
            // Find the largest double less than 3
            long bits = BitConverter.DoubleToInt64Bits(3);
            double a = BitConverter.Int64BitsToDouble(bits - 1);
            double b = Math.Floor(a);
            // Print them using the default conversion to string...
            Console.WriteLine(a.ToString() + " " + b.ToString());
            // Now use round-trip formatting...
            Console.WriteLine(a.ToString("r") + " " + b.ToString("r"));
        }
    }
    

    Output:

    3 2
    2.9999999999999996 2
    

    Now double.ToString() is documented with:

    This version of the ToString method implicitly uses the general numeric format specifier (“G”) and the NumberFormatInfo for the current culture.

    … and the general numeric format specifier docs state:

    The precision specifier defines the maximum number of significant digits that can appear in the result string. If the precision specifier is omitted or zero, the type of the number determines the default precision, as indicated in the following table.

    … where the table shows that the default precision for double is 15. If you consider 2.9999999999999996 rounded to 15 significant digits, you end up with 3.

    In fact, the exact value of a here is:

    2.999999999999999555910790149937383830547332763671875
    

    … which again, is 3 when regarded with 15 significant digits.

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

Sidebar

Related Questions

Getting double free for below code, if a long string passed. I tried all
double? test = true ? null : 1.0; In my book, this is the
double radius = 5; double area = Math.PI * Math.pow(radius, 2); // System.out.println(area); BigDecimal
double s = 12.20; Console.WriteLine(s); It prints 12.2 but I need it to print
Double quotes can be escaped like this: string test = @He said to me,
double a = 18.565 return Math.Round(a,2) ..returns 18.57. For every other number I tried
def double(a) a*2 end method_object = method(:double) and here's my question, how does this
A double quote looks like this . If I put this inside a python
Implement double sqrt(double x) in C++ without using std library. This is a facebook
Double has Double.compare for comparing two double primitives. Why doesn't Integer have one? I

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.