Created
March 13, 2013 13:49
-
-
Save eminetto/5152239 to your computer and use it in GitHub Desktop.
Filtro de Float
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Core\Filter; | |
use Zend\Filter\AbstractFilter; | |
/** | |
* Faz o filtro de valores convertendo para float | |
* @category Core | |
* @package Filter | |
*/ | |
class Float extends AbstractFilter | |
{ | |
/** | |
* Defined by Zend\Filter\FilterInterface | |
* | |
* Returns (float) $value | |
* | |
* @param string $value | |
* @return float | |
*/ | |
public function filter($value) | |
{ | |
if ($value === (string) (float) $value || is_float($value)) { | |
return (float) $value; | |
} | |
$value = str_replace('.', '', $value); | |
$value = str_replace(',', '.', $value); | |
return (float) ((string) $value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment