Example 1 — Converting Text to Floats
Use floatval() to turn strings and integers into floats, and check the result with var_dump().
<?php
var_dump(floatval("12.5"));
var_dump(floatval("1.5abc"));
var_dump(floatval("abc"));
var_dump(floatval(10)); How It Works
- "12. 5" is a clean number, so the result is float(12.5).
- "1. 5abc" starts with 1.5, so PHP keeps 1.5 and ignores the letters.
- "abc" has no leading number, so the result is float(0).
- The integer 10 is turned into the float 10. var_dump() shows floats without a trailing .0.

