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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:40:46+00:00 2026-05-29T08:40:46+00:00

I have a Double which I created like this: Double d = Double.parseDouble( 27.86753

  • 0

I have a Double which I created like this:

Double d = Double.parseDouble( "27.86753" ); // All the digits of this double value are 27.867530822753906

This particular double can also be represented by a float, so Java drops the rest of my digits. How can I force Java to give me the true double representation (all of the digits) of this value?

  • 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-29T08:40:47+00:00Added an answer on May 29, 2026 at 8:40 am

    Oh, man, interesting. You want to learn exactly how double does it inaccurately.

    I think new BigDecimal(double).toString() will give you all of the incorrect digits, since BigDecimal represents a number with a precisely specified precision.

    EDIT: Ohhhhhhhh, I think I see what’s going on.

    Let me try to explain it like this: Double.toString returns the least precise String such that Double.parseDouble will return exactly the same double — just enough digits to “uniquely identify” the exact IEEE 754 value, though the actual value may have more digits than are printed. Just because Double.toString isn’t giving you as many digits as you expect doesn’t mean that the actual IEEE 754 double-precision value is being rounded to that many digits. new BigDecimal(double).toString will return the exact IEEE-754 value being stored.

    UPDATE:

    What’s going on is that when it prints out 27.86753, it’s actually internally a more precise value than the digits you’re quoting as the correct answer, 27.867530822753906. That’s just because toString is designed to print out only as much as necessary to ensure that Double.parseDouble(Double.toString(value)) is a no-op.

    I ran the following code:

    public static void main(String[] args) {
      double dWithFloat = Double.parseDouble(Double.toString(Float.parseFloat("27.86753")));
      double dJustParsed = Double.parseDouble("27.86753");
      System.out.println(dWithFloat);
      System.out.println(dJustParsed);
    
      BigDecimal bigFromFloat = new BigDecimal(dWithFloat);
      BigDecimal bigJustParsed = new BigDecimal(dJustParsed);
      System.out.println(bigFromFloat); 
        // prints the exact value from the double,
        // doesn't round or truncate like Double.toString
      System.out.println(bigJustParsed);
    

    }

    and it printed out

    27.867530822753906 // Double.toString(Double.parseDouble(Double.toString(Float.parseFloat("27.86753"))));
    27.86753 // Double.toString(Double.parseDouble("27.86753")) is indeed a no-op
    27.86753082275390625 // This is the _actual_ value from D.parseD(D.toString(F.parseF("27.86753")))
    27.867529999999998580051396857015788555145263671875 // This is the actual value from D.parseD("27.86753")
    

    And indeed, this second value is noticeably closer to 27.86753, by a margin of something like 0.0000008.

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

Sidebar

Related Questions

Supposing I have a 2 dimensional array which was created with something like this,
I have double values which I would like to convert to String values with
I have this 2D array (say double[10][10]) which contain some 1.0 and 10.0, rest
I have a specific requirement that all children of a particular JComponent have double
I have some MSVC++ compiled DLL's for which I have created COM-like (lite) interfaces
In a C++ code I have a matrix of double variables which I print
I have table which contains double values stored in mysql database ...I need to
I have a bean where I have a field CustAmount which is double, I
I have an exe file which runs OK when I double clik on it
Let’s say I have double length that can be either a real length or

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.