Home > database >  I convert Int to Float but the Id-Type doesn't change
I convert Int to Float but the Id-Type doesn't change

Time:09-26

I convert int to float and input 1.23 to 'a' but output is 1 what is wrong?

int a = 123;
static_cast<float>(a);
cout << typeid(a).name(); //int

cin >> a; //1.23
cout << a;  //1


return 0;

CodePudding user response:

You have to asign the return value to a variable of the preffered Type:

float result = static_cast<float>(your_var);
  • Related