fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. int main()
  5. {
  6. const int counts[] = { 166652, 166675, 166668, 166663, 166678, 166664 } ;
  7.  
  8. std::cout << std::fixed << std::setprecision(2) ;
  9.  
  10. for( int v : counts )
  11. {
  12. const double pct = ( v * 100 ) / 1000000 ; // integer division
  13. std::cout << pct << ' ' ;
  14. }
  15. std::cout << '\n' ;
  16. // prints: 16.00 16.00 16.00 16.00 16.00 16.00
  17.  
  18. for( int v : counts )
  19. {
  20. const double pct = ( v * 100.0 ) / 1000000 ;
  21. std::cout << pct << ' ' ;
  22. }
  23. std::cout << '\n' ;
  24. // prints: 16.67 16.67 16.67 16.67 16.67 16.67
  25. }
  26.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
16.00 16.00 16.00 16.00 16.00 16.00 
16.67 16.67 16.67 16.67 16.67 16.67