Hi everyone. I have a simple question that i don't knot it :
I have the next division :
296/91=3,2527472527472527472527472527473
I want print the result of it, but only with 4 decimals. What is the command ?
Thank you!
Hi everyone. I have a simple question that i don't knot it :
I have the next division :
296/91=3,2527472527472527472527472527473
I want print the result of it, but only with 4 decimals. What is the command ?
Thank you!
Look up the stream manipulators in the iomanip header such as setprecision.
[edit]Code sample follows:[/edit]
Code:#include <iostream> #include <iomanip> int main() { double p = 12.345467889; std::cout << p << std::endl; std::cout << std::setprecision(8) << p << std::endl; return 0; }
Last edited by hk_mp5kpdw; 03-02-2011 at 01:53 PM.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens