fork download
  1. #include <iostream>
  2.  
  3. #include <boost/multiprecision/cpp_dec_float.hpp>
  4.  
  5. using namespace boost::multiprecision;
  6.  
  7. int main() {
  8. long double a = 0.1;
  9. std::cout << std::setprecision(100) << a << std::endl;
  10.  
  11. cpp_dec_float_100 b("0.1");
  12. std::cout << std::setprecision(100) << b << std::endl;
  13.  
  14. cpp_dec_float_100 counter;
  15. do {
  16. std::cout << "Loop " << std::endl;
  17. counter += cpp_dec_float_100("0.1");
  18. } while (counter != 1.0);
  19.  
  20.  
  21. float amountOfProduct = 254.99f;
  22. unsigned long int quantity = 100000000;
  23. float amountOfCheckout = amountOfProduct*quantity;
  24.  
  25. std::cout << std::setprecision(30) << amountOfCheckout << std::endl;
  26.  
  27. cpp_dec_float_50 amountOfProduct2 = cpp_dec_float_50("254.99");
  28. cpp_dec_float_50 quantity2 = cpp_dec_float_50("100000000");
  29. cpp_dec_float_50 amountOfCheckout2 = cpp_dec_float_50(amountOfProduct2*quantity2);
  30.  
  31. std::cout << std::setprecision(30) << amountOfCheckout2 << std::endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 15416KB
stdin
Standard input is empty
stdout
0.1000000000000000055511151231257827021181583404541015625
0.1
Loop 
Loop 
Loop 
Loop 
Loop 
Loop 
Loop 
Loop 
Loop 
Loop 
25499000832
25499000000