C++ floating point to integer type conversions

前端 未结 8 2286
长发绾君心
长发绾君心 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:26

    For most cases (long for floats, long long for double and long double):

    long a{ std::lround(1.5f) }; //2l
    long long b{ std::llround(std::floor(1.5)) }; //1ll
    

提交回复
热议问题