Rounding up problem

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 7
Reputation: Quakes is an unknown quantity at this point 
Solved Threads: 0
Quakes Quakes is offline Offline
Newbie Poster

Rounding up problem

 
0
  #1
Mar 4th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Rounding up problem

 
0
  #2
Mar 4th, 2008
> 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
  1. std::cout << std::fixed << std::setprecision(8)
  2. // 8 digits *after* decimal point
  3. << 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.
Last edited by vijayan121; Mar 4th, 2008 at 3:21 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 7
Reputation: Quakes is an unknown quantity at this point 
Solved Threads: 0
Quakes Quakes is offline Offline
Newbie Poster

Re: Rounding up problem

 
0
  #3
Mar 4th, 2008
Thanks very much, knew it would be something simple like that.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC