I want to convert long to float/double but casting rounds the value. How can I convert without it being rounded?
Here is my code:
#include <cmath>
#include <iostream>
int main()
{
const uint32_t UW = 1000;
int txPower = 3012916;
long x = std::stoi("3012916") * UW;
std::cout << "x = " << x << std::endl;
auto xFloat = (float)x;
std::cout << "x float = " << xFloat << std::endl;
auto xDouble = (double)x;
std::cout << "xDouble = " << xDouble << std::endl;
std::cout << "xDouble value cast = " << (double)3012916000 << std::endl;
return 0;
}
Yields this output:
x = 3012916000
x float = 3.01292e+09
xDouble = 3.01292e+09
xDouble value cast = 3.01292e+09
Help!