Typecasting vs function to convert variable type
Is there any difference between typecasting and using a function to convert a variable to some type?
If there are, when one of those should be used instead of the other?
Verified Answer (87 Votes) ✓
There's no difference in the resulting value, just:
(float)is a language feature and very quick
floatval()incurs the overhead of a function call (minimal, but nonetheless...)
floatval()as a function can be used in ways that
The last point is, I believe, the main reason for
floatval's existence: so each casting operation has a function equivalent, which can be useful in some circumstances.