conversion from double to unsigned int

前端 未结 3 574
无人共我
无人共我 2021-01-17 18:02

I am facing a problem with the conversion of value from Double to int. I try to run the following code :

int main()
{
    double val_d= 6.25e-05;
    cout &l         


        
3条回答
  •  庸人自扰
    2021-01-17 19:04

    difference in rounding.

    1. (1/val_d) - double is rounded to the nearest possible number that can be represented with double precision; (ex.: 3.6999999999999999 == 3.7)
    2. (unsigned int ) (1/val_d) - when casting to int decimal part is truncated, that results on rounding down (ex.: int(3.6) == 3

提交回复
热议问题