JBZoo\SimpleTypes\Parser::cleanValue PHP Method

cleanValue() public method

public cleanValue ( string $value ) : float
$value string
return float
    public function cleanValue($value)
    {
        $result = trim($value);
        $result = preg_replace('#[^0-9-+eE,.]#', '', $result);
        if (!preg_match('#\\d[eE][-+]\\d#', $result)) {
            // remove exponential format
            $result = str_replace(array('e', 'E'), '', $result);
        }
        $result = (double) str_replace(',', '.', $result);
        $result = round($result, Formatter::ROUND_DEFAULT);
        return $result;
    }

Usage Example

Beispiel #1
0
 /**
  * @param float $number
  * @param bool  $getClone
  * @return $this
  */
 public function division($number, $getClone = false)
 {
     $divider = $this->_parser->cleanValue($number);
     return $this->_modifer($this->_value / $divider, 'Division with "' . $divider . '"', $getClone);
 }