Simple type casts:
- Convert to integer: (int)
- Convert to single-precision: (double)
- Convert to long integer: (long)
C++ type cast example:
Sample code download: Box.net|4Shared|Dropbox|GoogleP.S. The type-casting syntax is the same in C++ and PHP, so only C++ examples are shown here.
Another short cast: static_cast
Besides the (int) and (double) casts above, there is another casting method that seems safer and less prone to problems: static_cast<>. However, this method doesn't seem to work in PHP.Format: static_cast<target type>(variable to be converted)
For example, to convert the data in the int variable x to float, the code is:
static_cast< int >(x);


