I'm attempting to read lines of a file and store the contents of the line in an object.

This is an example line (x,y,z co-ordinates) :

-12.852222 32.548111 -934.306681

My problem is that my program is rounding these numbers up and I need absolute precision. Having read one line, storing the numbers in the object and printing out the values to make sure they are correct they now look like this:

X: -12.8522 Y: 32.5481 Z: -934.307

This is probably something to do with the types I'm using. The variables are declared as doubles in the object. I've also tried floats, which still gives the same problems.

If you want to see any of my code, please just ask.

Thanks

Recommended Answers

All 2 Replies

> printing out the values to make sure they are correct they now look like this ...
the initial default precision for a stream is 6. to print out more decimal digits, do something like

std::cout << std::fixed << std::setprecision(8) 
          // 8 digits *after* decimal point
          << value ;

> I need absolute precision.
you will not get absolute precision with floating point values.
if the precision of a long double is not sufficient, you would either use integral types (numerator,denominator) or use a high precision arithmetic library.

Thanks very much, knew it would be something simple like that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.