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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:46:21+00:00 2026-05-26T17:46:21+00:00

Is this a glitch in Java? I go to solve this expression: 3.1 –

  • 0

Is this a glitch in Java?

I go to solve this expression: 3.1 – 7.1

I get the answer: -3.9999999999999996

What is going on here?

  • 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-26T17:46:21+00:00Added an answer on May 26, 2026 at 5:46 pm

    A great explanation can be found here. http://www.ibm.com/developerworks/java/library/j-jtp0114/

    Floating point arithmetic is rarely exact. While some numbers, such
    as 0.5, can be exactly represented as a binary (base 2) decimal (since
    0.5 equals 2-1), other numbers, such as 0.1, cannot be. As a result, floating point operations may result in rounding errors, yielding a
    result that is close to — but not equal to — the result you might
    expect. For example, the simple calculation below results in
    2.600000000000001, rather than 2.6:

    double s=0;
    
    for (int i=0; i<26; i++)
        s += 0.1;
    System.out.println(s); 
    

    Similarly, multiplying .1*26 yields a result different from that of
    adding .1 to itself 26 times. Rounding errors become even more serious
    when casting from floating point to integer, because casting to an
    integral type discards the non-integral portion, even for calculations
    that “look like” they should have integral values. For example, the
    following statements:

      double d = 29.0 * 0.01;
      System.out.println(d);
      System.out.println((int) (d * 100));
    

    will produce as output:

     0.29
      28  
    

    which is probably not what you might expect at first.

    See the provided reference for more information.

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

Sidebar

Related Questions

This is my first post here and I wanted to get some input from
I have this MySQL Query glitch in my VB.NET program. Here is the query
Okay - this is the dumbest glitch I have seen in a while: <!DOCTYPE
I wanted to know if anyone else has experienced this 'glitch' between browsers with
Apologies in advange for the newbie question. I can't get my head around this,
this is a small, but very annoying , glitch in my form. I have
I'm not sure if this is a glitch/quirk in the latest Firefox and Chrome,
I'll get right to it. Here's a pic of what I'm talking about in
Anyone with any ideas on what's causing this weird glitch with the google maps
edit: this is now solved, see my answer below The situation: User clicks on

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.