note 90753 added to language.types.float

From: Date: Fri, 08 May 2009 03:34:07 +0000
Subject: note 90753 added to language.types.float
Groups: php.notes 
Request: Send a blank email to php-notes+get-154343@lists.php.net to get a copy of this message
In MySQL, many floating point number types can have a range specified using 2 values, the "precision" and the "scale" E.g. 'float(precision,scale)' for the datatype. This syntax means a number may be <precision> bits long, but may only have <scale> bits after the decimal point. E.g. a 'float(5,2)' field may have the values -999.99 to 999.99. Here is a function to validate a PHP float using this syntax: <?php function validate_float($float, $precision, $scale) { $max = (float)str_pad("", $precision-$scale, '9').'.'.str_pad("", $scale, '9'); $min = (float)"-$max"; if(($float < $min) || ($float > $max)) return false; else return true; } ?> ---- Server IP: 117.104.162.229 Probable Submitter: 58.96.44.86 (proxied: 58.96.44.86) ---- Manual Page -- http://www.php.net/manual/en/language.types.float.php Edit -- https://master.php.net/note/edit/90753 Del: integrated -- https://master.php.net/note/delete/90753/integrated Del: useless -- https://master.php.net/note/delete/90753/useless Del: bad code -- https://master.php.net/note/delete/90753/bad+code Del: spam -- https://master.php.net/note/delete/90753/spam Del: non-english -- https://master.php.net/note/delete/90753/non-english Del: in docs -- https://master.php.net/note/delete/90753/in+docs Del: other reasons-- https://master.php.net/note/delete/90753 Reject -- https://master.php.net/note/reject/90753 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154343) next »