Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created March 13, 2013 13:49
Show Gist options
  • Save eminetto/5152239 to your computer and use it in GitHub Desktop.
Save eminetto/5152239 to your computer and use it in GitHub Desktop.
Filtro de Float
<?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