fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <typeinfo>
  4. using namespace std;
  5.  
  6. class Item {
  7. public:
  8. int quantity;
  9. float price; // try with float (value is truncated), double, long double
  10. };
  11. int main() {
  12. Item item1{10,14.2}, item2{1000000, 1.0000000001};
  13. auto total_price = item1.quantity*item1.price + item2.quantity*item2.price;
  14. cout <<"Type "<< typeid(total_price).name() <<": "
  15. << std::fixed<<std::setw(20) << std::setprecision(8) << total_price << endl;
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Type f:     1000142.00000000