note 106145 modified in language.types.float by danbrown
| From: | danbrown@php.net | Date: | Fri, 14 Oct 2011 22:40:28 +0000 |
| Subject: | note 106145 modified in language.types.float by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183894@lists.php.net to get a copy of this message | ||
Convert locale string into float number
<?php
function str2num($str){
if(strpos($str, '.') < strpos($str,',')){
$str = str_replace('.','',$str);
$str = strtr($str,',','.');
}
else{
$str = str_replace(',','',$str);
}
return (float)$str;
}
str2num('25,01'); //25.01
str2num('2.5,01'); //25.01
str2num('25.01'); //25.01
str2num('2,5.01'); //25.01
?>
--was--
Convert locale string into float number
function str2num($str){
if(strpos($str, '.') < strpos($str,',')){
$str = str_replace('.','',$str);
$str = strtr($str,',','.');
}
else{
$str = str_replace(',','',$str);
}
return (float)$str;
}
str2num('25,01'); //25.01
str2num('2.5,01'); //25.01
str2num('25.01'); //25.01
str2num('2,5.01'); //25.01
http://php.net/manual/en/language.types.float.php