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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:13:26+00:00 2026-06-12T19:13:26+00:00

I have a floating point number stored in a binary file 0.9999833107. When I

  • 0

I have a floating point number stored in a binary file 0.9999833107. When I read the number in it is either truncated or extended depending on whether I use float or double to store it. I read in the binary with the following code:

public double readFloat(RandomAccessFile fp){

    byte[] data = new byte[4];

    try {

        data[0] = fp.readByte();
        data[1] = fp.readByte();
        data[2] = fp.readByte();
        data[3] = fp.readByte();

    } catch (IOException e) {
            e.printStackTrace();
            return 0;
    }

    ByteBuffer buffer = ByteBuffer.wrap(data);

    return buffer.getDouble();
}

This method returns 0.9999833106994629. When I change the method to output a float the value returned is 0.9999833. Does anyone have any idea how I can get the number out that was written into the file?

  • 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-12T19:13:28+00:00Added an answer on June 12, 2026 at 7:13 pm

    If you’re only storing 4 bytes, you could only possibly have 9 guaranteed significant digits of accuracy, as there are only 4294967296 values representable within 32 bits – and that’s assuming you could use all the bits as mantissa, with nothing for exponent or sign.

    I think it’s far more likely that this was originally a value “close to” 0.9999833107, represented as a double, and then truncated to a float for storage. Note that 0.9999833107 itself can’t be stored exactly as a double – the closest double value to that is 0.9999833107000000165243136507342569530010223388671875.

    In other words, when reading it as a float you are getting “the number that was written into the file”. It may not have been the number you had before the conversion for storage, but it’s the number that was actually written into the file.

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

Sidebar

Related Questions

What is the best way to parse a large floating point file stored in
I have a floating point number that I want to truncate to 3 places
I have a string with a floating point number in it, but I can't
I have a column that is currently a floating-point number and I need to
I have a floating point number that have more decimal digits, for example: float
I have a floating point number in JavaScript, like 42.563134634634. I want to display
Suppose I have a hex number 4072508200000000 and I want the floating point number
I have a char array representing a double precision floating point number in hex
I have periodic data with the index being a floating point number like so:
I have a floating point number in exponential format i.e. 4.1595246940817E-17 and I want

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.