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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:54:04+00:00 2026-06-07T12:54:04+00:00

Possible Duplicate: Floating point error in representation? So I am running this code to

  • 0

Possible Duplicate:
Floating point error in representation?

So I am running this code to read float string values from a a file and store the values in to an array. When the program reads in “0.333” from the file it creates a new float value but the value is converted into 0.33329999446868896! Why is this? And how can I fix this issue? The matrices are declared as follows:

this.matrix = new double[this.getRow()][this.getCol()];
this.bMatrix = new double[this.getRow()];  

try {
        // make sure no blank lines at the end of the file.
        for (int i = 0; (strLine = reader.readLine()) != null; i++) {  
            System.out.println("Line from file #" + i + " " + strLine);
            String[] columns = strLine.trim().split("\\s+");
            for (int j = 0; j < columns.length; j++) {
                if (j < (columns.length - 1)) {
                    //A-matrix
                    this.matrix[i][j] = new Float(columns[j]).floatValue();
                    System.out.println("Element added to A-matrix: " + columns[j]);
                } else {
                    // B-matrix
                    bMatrix[i] = new Float(columns[j]).floatValue();
                    System.out.println("Element added to B-matrix: " + columns[j]);

                }
            }
        }
        showMatrix();
    } catch (IOException | NumberFormatException e) {
        reader.close();

    }
}

Thanks for any assistance.

  • 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-07T12:54:06+00:00Added an answer on June 7, 2026 at 12:54 pm

    This has to do with the way floating point numbers are represented in binary. Essentially, you can’t precisely represent 0.333. The closest you can get is the number you see. If you want a shorter version for printing, use StringFormatter or something before you output your values.

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

Sidebar

Related Questions

Possible Duplicate: Dealing with accuracy problems in floating-point numbers Code: float flt = 78983636;
Possible Duplicate: Floating point issue in C #include<stdio.h> main() { int a,b; float f;
Possible Duplicate: Extract decimal part from a floating point number in C I would
Possible Duplicate: Floating point inaccuracy examples PHP rounding issue - Is this a bug?
Possible Duplicate: Floating point comparison When I run the code below I get the
Possible Duplicate: Precision of Floating Point Can you compare floating point values exactly to
Possible Duplicate: What is a simple example of floating point/rounding error? When I execute
Possible Duplicate: Strange floating-point behaviour in a Java program I came across this weird
Possible Duplicate: Java floating point arithmetic What is special about this double math in
Possible Duplicate: Floating point comparison I have some simple C code and the output

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.