I am trying to validate a float. I need to test if a string variable is a float. i tried the is_float function but it doesnt seem to work with string variables
die ('<div style="clear:both;float:left;"><h3>Sorry your duration must be a number in hours.</h3>
<table><tr><td>Click here to go back -</td><td> <a href="?area=1" class="button" >Back </a></td></tr></table></div></div>');
07-02-2007, 05:04 PM
is_float doesn't work with strings.
Try converting $duration to an integer first using the intval() function.
07-02-2007, 05:41 PM
Hi thanks for the suggestion. However will converting my string in to an interger truncate the decimal digits? As the user may have inputed 1.5 as the duration.
07-02-2007, 05:43 PM
You can use floatval() to convert it to a float.
07-02-2007, 05:47 PM
floatval() will turn anything (scalar) into a float, so probably not very useful: