fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. float currentValue = 0.6125213412452143000000f;
  7. int roundVal = 100;
  8. cout<<"currentValue * roundVal = "<<currentValue * roundVal<<endl;
  9. cout<<"std::roundf(currentValue * roundVal) = "<<std::roundf(currentValue * roundVal)<<endl;
  10. cout<<"std::roundf(currentValue * roundVal) / roundVal = "<<std::roundf(currentValue * roundVal) / roundVal<<endl;
  11. float calculation = std::roundf(currentValue * roundVal) / roundVal;
  12. cout<<std::to_string(calculation)<<endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
currentValue * roundVal = 61.2521
std::roundf(currentValue * roundVal) = 61
std::roundf(currentValue * roundVal) / roundVal = 0.61
0.610000