Convert between units

@param float $value
@param string $fromUnit (using class constants)
@param string $toUnit (using class constants)
@return float convertedValue
@throws \Exception
161896
public function convert($value, $fromUnit, $toUnit) {
		$fromUnit = strtoupper($fromUnit);
		$toUnit = strtoupper($toUnit);

		if (!isset($this->_units[$fromUnit]) || !isset($this->_units[$toUnit])) {
			throw new CalculatorException('Invalid Unit');
		}

		if ($fromUnit === static::UNIT_MILES) {
			$value *= $this->_units[$toUnit];
		} elseif ($toUnit === static::UNIT_MILES) {
			$value /= $this->_units[$fromUnit];
		} else {
			$value /= $this->_units[$fromUnit];
			$value *= $this->_units[$toUnit];
		}
		return $value;
	}
270195
public static function convert($value, $to, $from)
    {
        if ($from instanceof Measure === false || $to instanceof Measure === false) {
            throw new Exception('`from` or `to` parameter is not a Measure');
        }
        if ($from->type !== $to->type) {
            throw new Exception('Measures have different types');
        }
        if ($from->id == $to->id) {
            return $value;
        }
        $converterClass = isset(static::$converters[$to->type]) === true
            ? static::$converters[$to->type]
            : 'DevGroup\Measure\converters\DefaultMeasureTypeConverter';
        return $converterClass::convert($value, $to, $from);
    }
761130
public function removeClassName($from = 'class', $value = null)
    {
        $classes = explode(' ', (string) $this->getAttribute($from));

        $value = array_diff($classes, is_string($value) ? explode(' ', $value) : $value);

        return $this->set($from, implode(' ', array_unique($value)));
    }
1017298
public double to(final Unit unit) {
		requireNonNull(unit);
		return unit.convert(_value, Unit.METERS_PER_SECOND);
	}
447296
public function convertTo($value, $to, array $exclude = array(), $max_nesting_level = null)
  {
    $this->level             = 0;
    $this->max_nesting_level = is_null($max_nesting_level) ? 30 : intval($max_nesting_level);

    switch (strtolower($to))
    {
      case ConversionEnum::ARRAY_CONVERSION:
        return $this->toArray($value, $exclude);
        break;
      case ConversionEnum::JSON_CONVERSION:
        return $this->toJSON($value, $exclude);
        break;
      case ConversionEnum::OBJECT_CONVERSION:
        return $this->toObject($value, $exclude);
        break;
      case ConversionEnum::PUBLIC_OBJECT_CONVERSION:
        return $this->toObject($value, $exclude, true);
        break;
      case ConversionEnum::STRING_CONVERSION:
        return $this->toString($value, $exclude);
        break;
    }

    return $this->fail($value, $to);
  }
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;
    }
207754
def unit(self, value):
        

        if isinstance(value, TimeUnit):
            self._unit = value
        else:
            self._unit = TimeUnit(value)
21543
public static function conversionFailed($value, $toType)
    {
        $value = strlen($value) > 32 ? substr($value, 0, 20) . '...' : $value;

        return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType);
    }
388204
public static function convertInto(float $time, string $unit, string $destUnit)
    {
        if (!$time) {
            return 0;
        }

        self::validateUnit($unit);
        self::validateUnit($destUnit);

        $destMultiplier = self::$map[$destUnit];
        $sourceMultiplier = self::$map[$unit];

        $time = $destMultiplier / ($time * $sourceMultiplier);

        return $time;
    }
1173736
def convert(self, value, fromunits, tounits):
        ''''''
        if fromunits == tounits:
            return value
        if (fromunits,tounits) in self.unitmap:
            return value * self.unitmap[(fromunits,tounits)]
        if (tounits,fromunits) in self.unitmap:
            return value / self.unitmap[(tounits,fromunits)]
        raise fgFDMError("unknown unit mapping (%s,%s)" % (fromunits, tounits))
20950
public function from($value, $unit)
    {
        $this->base_unit = $this->value = null;

        $key = strtolower($unit);

        if (empty($this->units[$key]['base'])) {
            throw new OutOfBoundsException('Unit does not exist');
        }

        if (!isset($this->units[$key]['conversion'])) {
            throw new OutOfBoundsException("Conversion is not set for unit $unit");
        }

        $this->base_unit = $this->units[$key]['base'];
        $this->value = $this->toBase($value, $this->units[$key]);
        return $this;
    }
810352
function Amount(value, unit) {
  if (!(this instanceof Amount))
    return new Amount(value, unit);

  this.value = 0;
  this.unit = null;

  if (value != null)
    this.fromOptions(value, unit);
}
794890
public static boolean canConvert(Object fromObj, Class<?> to) {
        int weight = getConversionWeight(fromObj, to);

        return (weight < CONVERSION_NONE);
    }
715931
public static function convertMetric( $value, $from, $to, $precision = null ) {
        switch ($from . $to) {
            case 'incm':
                $value *= 2.54;
                break;
            case 'inmm':
                $value *= 25.4;
                break;
            case 'inpt':
                $value *= 72;
                break;
            case 'cmin':
                $value /= 2.54;
                break;
            case 'cmmm':
                $value *= 10;
                break;
            case 'cmpt':
                $value *= 72 / 2.54;
                break;
            case 'mmin':
                $value /= 25.4;
                break;
            case 'mmcm':
                $value /= 10;
                break;
            case 'mmpt':
                $value *= 72 / 25.4;
                break;
            case 'ptin':
                $value /= 72;
                break;
            case 'ptcm':
                $value *= 2.54 / 72;
                break;
            case 'ptmm':
                $value *= 25.4 / 72;
                break;
        }

        if ( !is_null($precision) ) {
            $value = round($value, $precision);
        }

        return $value;
    }
435597
@SuppressWarnings({ "unchecked", "rawtypes" })
	public static final <TO, FROM> TO convert(Class<TO> to, FROM from) {

		// Convert null value
		if (from == null || to == null) {
			return null;
		}

		// Convert "null" String to null
		if ("null".equals(from)) {
			return null;
		}

		// Class is same
		if (to == Object.class || from.getClass() == to) {
			return (TO) from;
		}

		// BSON conversion
		boolean isFromMap = from != null && from instanceof Map;
		if (isFromMap) {
			Object subValue = getSubValue((Map) from);
			if (subValue != null) {
				return convert(to, subValue);
			}
		}

		// Convert FROM -> TO
		DataConverterKey<TO, FROM> key = new DataConverterKey<TO, FROM>(to, (Class<FROM>) from.getClass());
		DataConverter<TO, FROM> converter = (DataConverter<TO, FROM>) converters.get(key);
		if (converter != null) {
			return converter.convert(from);
		}

		// Convert any -> TO
		converter = (DataConverter<TO, FROM>) defaultConverters.get(to);
		if (converter != null) {
			return converter.convert(from);
		}

		// Converter not found
		throw new IllegalArgumentException("Unable to convert " + from.getClass() + " to " + to
				+ ", converter not found in DataConverterRegistry!");
	}
1318598
public function convert($value, $from, $to, $decimals = 2)
    {
        return (float) $this->from($value, $from)->to($to, $decimals, !empty($decimals));
    }
143497
public function negativeRelativeDateFilter($field, $fromUnit = self::RELATIVE_DATE_FILTER_UNIT_MINUTES, $fromInterval, $toUnit = self::RELATIVE_DATE_FILTER_UNIT_MINUTES, $toInterval = 0, $dateFormat = self::RELATIVE_DATE_FILTER_DATEFORMAT, $isNegative = false) {
        return $this->relativeDateFilter($field, $fromUnit, $fromInterval, $toUnit, $toInterval, $dateFormat, true);	    
	}