| | |
Rounding up problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
> 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
> I need absolute precision.
you will not get absolute precision with floating point values.
if the precision of a
the initial default precision for a stream is 6. to print out more decimal digits, do something like
C++ Syntax (Toggle Plain Text)
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. Last edited by vijayan121; Mar 4th, 2008 at 3:21 pm.
![]() |
Similar Threads
- seperate float's decimal portion (C)
- Division Problem (C#)
- bar image reset problem (Pascal and Delphi)
- A problem in my bar image to control (Pascal and Delphi)
- rounding array elements (C++)
- Newbie Problem (Python)
- currency rounding difficulties (VB.NET)
- rounding corners of a table (HTML and CSS)
- Rounding with Microsoft Visual Studio .NET 2003 (C++)
Other Threads in the C++ Forum
- Previous Thread: Help with C++ code to calculate a series?
- Next Thread: Swap two numbers with pointers
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






