C++ floating point to integer type conversions

前端 未结 8 2217
长发绾君心
长发绾君心 2020-12-01 08:50

What are the different techniques used to convert float type of data to integer in C++?

#include 

using namespace std;
struct database {
  i         


        
相关标签:
8条回答
  • 2020-12-01 09:41

    Check out the boost NumericConversion library. It will allow to explicitly control how you want to deal with issues like overflow handling and truncation.

    0 讨论(0)
  • 2020-12-01 09:47

    Normal way is to:

    float f = 3.4;
    int n = static_cast<int>(f);
    
    0 讨论(0)
提交回复
热议问题