Recent Posts

Showing posts with label cast. Show all posts
Showing posts with label cast. Show all posts

How to parse string to float in PHP

If you want to parse a string to float type then you can use floatval:

float floatval  ( mixed $var  ) - Gets the float value of a string.

<?php
 $var = '122.34343The';
 $float_value_of_var = floatval($var);
 echo $float_value_of_var; // 122.34343
?>
Or you can do a cast with (float):

$rootbeer = (float) $InvoicedUnits;