public function str2dec($value, $precision = 2)
    {
        $value = preg_replace('/[^\d,\.\-]+/', '', $value);
        if ($value === '') {
            return null;
        }
        if (($pos = strpos($value, ',')) === false && ($pos = strpos($value, '.')) === false) {
            $value = $value . str_pad('', $precision, '0');
            return (int)$value;
        }
        $distance = strlen($value) - $pos;
        if ($distance > $precision) {
            $value = substr($value, 0, $pos + $precision + 1);
        } else {
            do {
                $value .= '0';
            } while ($distance !== $precision-- && $precision > 0);
        }
        $value = str_replace([',', '.'], '', $value);

        return (int)$value;
    }
public function str2dec($value, $precision = 2)
    {
        $value = preg_replace('/[^\d,\.\-]+/', '', $value);
        if ($value === '') {
            return null;
        }
        if (($pos = strpos($value, ',')) === false && ($pos = strpos($value, '.')) === false) {
            $value = $value . str_pad('', $precision, '0');
            return (int)$value;
        }
        $distance = strlen($value) - $pos;
        if ($distance > $precision) {
            $value = substr($value, 0, $pos + $precision + 1);
        } else {
            do {
                $value .= '0';
            } while ($distance !== $precision-- && $precision > 0);
        }
        $value = str_replace([',', '.'], '', $value);

        return (int)$value;
    }
public function str2dec ( $ value , $ precision = 2 ) { $ value = preg_replace ( '/[^\d,\.\-]+/' , '' , $ value ) ; if ( $ value === '' ) { return null ; } if ( ( $ pos = strpos ( $ value , ',' ) ) === false && ( $ pos = strpos ( $ value , '.' ) ) === false ) { $ value = $ value . str_pad ( '' , $ precision , '0' ) ; return ( int ) $ value ; } $ distance = strlen ( $ value ) - $ pos ; if ( $ distance > $ precision ) { $ value = substr ( $ value , 0 , $ pos + $ precision + 1 ) ; } else { do { $ value .= '0' ; } while ( $ distance !== $ precision -- && $ precision > 0 ) ; } $ value = str_replace ( [ ',' , '.' ] , '' , $ value ) ; return ( int ) $ value ; }
Converts a decimal number as string to an integer.
@param string $value
@param int $precision
@return int
Converts a decimal number as string to an integer .