JBZoo\Utils\Filter::float PHP Method

float() public static method

public static float ( string $value, integer $round = 10 ) : float
$value string
$round integer
return float
    public static function float($value, $round = 10)
    {
        $cleaned = preg_replace('#[^0-9eE\\-\\.\\,]#ius', '', $value);
        $cleaned = str_replace(',', '.', $cleaned);
        preg_match('#[-+]?[0-9]+(\\.[0-9]+)?([eE][-+]?[0-9]+)?#', $cleaned, $matches);
        $result = isset($matches[0]) ? $matches[0] : 0.0;
        $result = round($result, $round);
        return (double) $result;
    }

Usage Example

Example #1
0
 /**
  * @param $exepted
  * @param $actual
  * @param $round
  * @dataProvider providerFloat
  */
 public function testFloat($exepted, $actual, $round = null)
 {
     if (null === $round) {
         isSame($exepted, Filter::_($actual, 'float'));
     } else {
         isSame($exepted, Filter::float($actual, $round));
     }
 }