note 108405 added to language.types.float

From: Date: Tue, 24 Apr 2012 10:58:45 +0000
Subject: note 108405 added to language.types.float
Groups: php.notes 
Request: Send a blank email to php-notes+get-187315@lists.php.net to get a copy of this message
The function returns 5 for 5,000 because if there is no decimal point, then the first strpos will be FALSE, and FALSE < 1 is TRUE so the condition will be still true. It should be checked whether strpos returns a valid position: <?php function str2num($str) { if (strpos($str, '.') !== FALSE && strpos($str, ',') !== FALSE && strpos($str, '.') < strpos($str,',')) { $str = str_replace('.','',$str); $str = strtr($str,',','.'); } else { $str = str_replace(',','',$str); } return (float)$str; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 188.26.20.143 ---- Manual Page -- http://www.php.net/manual/en/language.types.float.php Edit -- https://master.php.net/note/edit/108405 Del: integrated -- https://master.php.net/note/delete/108405/integrated Del: useless -- https://master.php.net/note/delete/108405/useless Del: bad code -- https://master.php.net/note/delete/108405/bad+code Del: spam -- https://master.php.net/note/delete/108405/spam Del: non-english -- https://master.php.net/note/delete/108405/non-english Del: in docs -- https://master.php.net/note/delete/108405/in+docs Del: other reasons-- https://master.php.net/note/delete/108405 Reject -- https://master.php.net/note/reject/108405 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187315) next »