I am trying to convert float value to long long int, using std::llround. But there seems to have some precision or "overflow" issue. I am not sure. The code looks like this:
#include <iostream>
int main()
{
float value = 123456.0f;
value *= 1.0E+6f;
std::cout << value << std::endl; // 1.23456e+11
std::cout << "after rounding: " << std::llround(value) << std::endl; // 123455995904
return;
}
The float value is 1.23456e+11, but using std::cout, the converted integer looks like 123455995904. I would expect it to be something like '123456000000'. How can I achieve that?
If I do the rounding directly on double value :
std::cout << "rounding double: " << std::llround(123456000000.0) << std::endl;
Then the long integer becomes expected: 123456000000.
(I am using Visual Studio 2019 in Windows 10.) Many thanks!