Converts a value from one unit to another.
@param int $to unit to convert to
@param mixed $val value to convert
@return float converted value
86
protected function convert($to, $val)
    {
        $val = $this->parseValue($val);

        return base_convert($val, $this->unit, $to);
    }
696553
protected function Eq( $val )
	{
		if  (! $val->getIsNumeric() ) return false;
		return  $this->ToInt( null ) == $val->ToInt( null );
	}
394976
function c($val) {
		$locale=setlocale(LC_NUMERIC,0);
		setlocale(LC_NUMERIC,'C');
		$out=(string)(float)$val;
		$locale=setlocale(LC_NUMERIC,$locale);
		return $out;
	}
1134071
public static function EqValues( $val1, $val2, &$res )
	{
		$res = false;

		if ( ! $val1 instanceof ValueProxy )
		{
			/**
			 * @var ValueProxyFactory $f
			 */
			$class = Type::FromValue( $val1 )->getFullName();
			$f = isset( ValueProxy::$valueFactory[ $class ] )
				? ValueProxy::$valueFactory[ $class ]
				: null;

			if ( is_null( $f ) ) return false;
			$val1 = $f->Create( $val1 instanceof XPath2Item ? $val1->getTypedValue() : $val1 );
		}

		if ( ! $val2 instanceof ValueProxy )
		{

			/**
			 * @var ValueProxyFactory $f
			 */
			$class = Type::FromValue( $val2 )->getFullName();
			$f = isset( ValueProxy::$valueFactory[ $class ] )
				? ValueProxy::$valueFactory[ $class ]
				: null;

			if ( is_null( $f ) ) return false;
			$val2 = $f->Create( $val2 instanceof XPath2Item ? $val2->getTypedValue() : $val2 );
		}

		switch ( ValueProxy::$conv_t[ $val1->GetValueCode() ][ $val2->GetValueCode() ] )
		{
			case -1:
				return $val2->Promote( $val1 )->TryEq( $val2, $res );

			case 0:
				return $val1->TryEq( $val2, $res );

			case 1:
				return $val1->TryEq( $val1->Promote( $val2 ), $res );

			default:
				if ( ValueProxy::$conv_t[ $val2->GetValueCode() ][ $val1->GetValueCode() ] == 1 )
					return $val2->Promote( $val1 )->TryEq( $val2, $res );
				return false;
		}
	}
588793
protected function Promote( $val )
	{
	    return $val instanceof DecimalProxy ? $val : new DecimalProxy( Convert::ToDecimal( $val, null ) );
	}
216936
public function convertValueTo(float $value, Uom $toUom): float
    {
        if ($toUom->getType() != $this->getType()) {
            throw new \InvalidArgumentException(
                'Conversion cannot be made between different type of Uom');
        }

        return ($value / $this->factor) * $toUom->factor;
    }
1146021
public static function fromCode($val)
    {
        switch(strtolower($val)) {
        case 'dkk':
            return self::DKK;
        case 'eur':
        case 'euro':
            return self::EUR;
        case 'nok':
            return self::NOK;
        case 'sek':
            return self::SEK;
        default:
            return null;
        }
    }
124684
public static function toFloat($input = false) {

        if ($input && Validate::isNumber($input)) {

            $float = (float) $input;
            if (Validate::isFloat($float)) {

                return $float;
            }
        }

        return false;
    }
119234
protected function realToBinary($val)
    {
        $bdata = self::typeBytes("2", 3); // 2 is 0010, type indicator for reals
        return $bdata.strrev(pack("d", (float)$val));
    }
872247
private function objectTransform($val)
    {
        if (! is_object($val)) {
            return $val;
        } elseif ($val instanceof Accessable) {
            return $this->serialize($val);
        } else {
            // Fallback for stdClass objects
            return json_decode(json_encode($val), true);
        }
    }
1050059
function value($type,$val) {
		switch ($type) {
			case self::PARAM_FLOAT:
				if (!is_string($val))
					$val=str_replace(',','.',$val);
				return $val;
			case \PDO::PARAM_NULL:
				return NULL;
			case \PDO::PARAM_INT:
				return (int)$val;
			case \PDO::PARAM_BOOL:
				return (bool)$val;
			case \PDO::PARAM_STR:
				return (string)$val;
			case \PDO::PARAM_LOB:
				return (binary)$val;
		}
	}
243895
public static function getSumOfDigits($val = null)
    {
        if (is_null($val)) {
            return null;
        }
        $nbs = str_split(pow(abs($val), 1));
        $result = 0;
        foreach ($nbs as $nb) {
            $result += (int) $nb;
        }
        return $result;
    }
234234
public static function getFibonacciItem($val = null)
    {
        if (is_null($val)) {
            return null;
        }
        if ($val==0) {
            return 0;
        } elseif ($val==1) {
            return 1;
        } elseif ($val>1) {
            return (self::getFibonacciItem($val-1) + self::getFibonacciItem($val-2));
        }
        return null;
    }
582778
protected function Mul( $val )
	{
		if ( ! $val instanceof ByteProxy ) throw new \InvalidArgumentException();
		return new IntProxy( $this->_value * $val->_value );
	}
1194588
protected function Eq( $val )
	{
		if ( ! $val instanceof BoolProxy ) return false;
		return  ( $this->_value instanceof CoreFuncs::$False && $val->getValue() instanceof CoreFuncs::$False ) ||
				( $this->_value instanceof CoreFuncs::$True && $val->getValue() instanceof CoreFuncs::$True ) ||
				( is_bool( $this->_value ) && is_bool( $val->getValue() ) && $this->_value == $val->getValue() );
		// return $this->_value == (bool)$val->_value;
	}
291697
protected function booleanValue($val)
    {
        if (is_numeric($val)) {
            return (bool) $val;
        } else {
            return (in_array(strtolower($val), array('true', 't', 'y', 'yes'), true) ? true : false);
        }
    }
288835
public static function format($value, $to, $from = null)
    {
        if ($to instanceof Measure === false) {
            throw new Exception('Unknown object');
        }
        if ($from instanceof Measure) {
            $value = static::convert($value, $to, $from);
        }
        $formatter = $to->use_custom_formatter == true ? $to->formatter : \Yii::$app->formatter;
        return strtr(
            $to->format,
            [
                '#' => $formatter->asDecimal($value),
                '$' => static::t($to->unit),
            ]
        );
    }