I've following code:
<?php
$amount = '$40.0';
?>
I want to get the number 40 only(in float form) from the string $40 i.e. after excluding the dollar sign. The number entered by user could be even float also like $345.894534. In case of float number, the entire float number I should get except the dollar sign. Also the variable can be empty at a times so the operation of typecasting should perform only when the variable contains some value. How should I do this in optimum way and by making use of ready made functions available in PHP? Can somebody please help me in this regard?Thanks in advance.
$amount = floatval(str_replace('$','','$40.2356')); //0 for empty string
$amount = '$345.894534';
$trimmed = ltrim($amount, "$"); // will return 345.894534