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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -