Printing float with precision 2 but without decimal(.) in C++ -


please consider code snippet shown below:

// setprecision example #include <iostream>     // std::cout, std::fixed #include <iomanip>      // std::setprecision  int main () {   double f =3.14159;   std::cout.precision(2);    std::cout << f*100 << '\n';   return 0; } 

what want print on screen 314 (i.e. print f without decimal precision 2)

i want thinking of first setting precision 2 , multiplying 100.

but seems precision applied on f*100. can suggest of way apply precision on f multiply number 100 , print precision 0?

multiply 100 , print precision 0.

int main () {   double f =3.14159;   std::cout.precision(0);    std::cout << std::fixed << f*100 << '\n';   return 0; } 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -