Previously I have declared b as a double and I now I want to convert back to int. Here is the code:Does this mean that now b is now a int where c = b? Am I right?Code:int c = static_cast<int>(b);
Previously I have declared b as a double and I now I want to convert back to int. Here is the code:Does this mean that now b is now a int where c = b? Am I right?Code:int c = static_cast<int>(b);
Code:double b = 2.5764; int c = 0; c = (int)b; //the int tells the comiler that you MEANT to convert from a double to and int //and the compiler won't warn you that you are losing some precision in the conversion // c == 2 == true // b == 2.5764 == true;
edit: actually "(int) b" means evaluate 'b' as an integer
Last edited by misplaced; 04-13-2005 at 04:27 AM.
i seem to have GCC 3.3.4
But how do i start it?
I dont have a menu for it or anything.
Does this mean that now b is now a int where c = b?c != bCode:double b = 3.5; int c = static_cast<int>(b); cout<<c<<endl; //3 cout<<b<<endl; //3.5
In addition, you might think you have 3.0 in a double variable, but really you have 2.9999999999999, and when you cast that to an int, you will get 2, and 2 != 2.99999999.
Last edited by 7stud; 04-13-2005 at 04:55 AM.
No, that statement takes the value of b, casts it to an int without changing the value of b, and stores that value in another variable c.Does this mean that now b is now a int where c = b? Am I right?
Therefore, c is an int, and b is still a double.