troubleshooting Question

question on c++ double variable and setprecision(2)

Avatar of c_hockland
c_hocklandFlag for Greece asked on
C++
2 Comments2 Solutions680 ViewsLast Modified:
hi ,
here is the code :

double c=0;
...
...

cout << endl;
            cout << " give a value for double variable c " ;
            cin >> c ;
            cout << endl << " the value you gave is " << c <<endl ;
            cout << " the value with 2 decimals is " << setprecision(2) << c << endl ;
            cout << " typing the value after 8 spaces " << setw(8) << c << endl;
            a=c;
            cout << endl << " the number in integer form is " << a << endl ;

but the output is wrong , more specificaly

i give 12.9999999

and it displays
13
13
13

why ??
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros