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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:01:49+00:00 2026-06-04T07:01:49+00:00

Possible Duplicate: Retain precision with Doubles in java Moving decimal places over in a

  • 0

Possible Duplicate:
Retain precision with Doubles in java
Moving decimal places over in a double

The class speaks for itself. If you execute this code, the double values seem to be overflowed somewhat, but then it does not happen for all values and besides, if you print the number directly the output is OK.

public class test {
    public static void main(String[] args){

        for (double f=1.36; f<1.40; f+=0.01) System.out.println(f); 
             //Prints 1.36
             //       1.37
             //       1.3800000000000001   ???????
             //       1.3900000000000001   ???????

            System.out.println(1.36); //Prints 1.36
            System.out.println(1.37); //Prints 1.37
            System.out.println(1.38); //Prints 1.38
            System.out.println(1.39); //Prints 1.39
    }
}

Can somebody shed some light? If this is a bug, whats´s the best way to fix it in the code?? Any magic workaround?

  • 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-04T07:01:50+00:00Added an answer on June 4, 2026 at 7:01 am

    If you format your printed output like this, you won’t see all those decimal places:

    System.out.printf("%.2f",yourVariable);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Retain precision with Doubles in java import static java.lang.System.out; public class q2{
Possible Duplicate: Retain precision with Doubles in java Floating point inaccuracy examples I know
Possible Duplicate: Working with latitude/longitude values in Java Duplicate: Working with latitude/longitude values in
Possible Duplicate: NSNumber retain count issue Hello, I have the following code: NSNumber *number
Possible Duplicate: How is release handled for @synthesized retain properties? I saw someone mention
Possible Duplicate: Difference between retain and copy? I'm learning iOS development right now and
Possible Duplicate: Is Java pass-by-reference? I found an unusual Java method today: private void
Possible Duplicate: NSString retain Count I am the beginner for iPhone programming. I am
Possible Duplicate: delegate not being called I declared a delegate in my appdelegate class,
Possible Duplicate: How do I make a list with checkboxes in Java Swing? 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.