Convert the given unit value into the best unit for its category
relative to the current measurement system.
16671
@Override
  public UnitValue convert(UnitValue value) {
    Unit src = value.unit();
    switch (src.category()) {
      case CONCENTR:
      case LIGHT:
        // Not available
        break;
        
      case ACCELERATION:
        return convert(value, Unit.METER_PER_SECOND_SQUARED, UnitFactors.ACCELERATION);
      case ANGLE:
        return convert(value, UnitFactorSets.ANGLE);
      case AREA:
        return convert(value, areaFactors());
      case CONSUMPTION:
        return convert(value, consumptionUnit());
      case DIGITAL:
        return convert(value, UnitFactorSets.DIGITAL_BYTES);
      case DURATION:
        return convert(value, UnitFactorSets.DURATION);
      case ELECTRIC:
        return convert(value, UnitFactorSets.ELECTRIC);
      case ENERGY:
        return convert(value, energyFactors());
      case FREQUENCY:
        return convert(value, UnitFactorSets.FREQUENCY);
      case LENGTH:
        return convert(value, lengthFactors());
      case MASS:
        return convert(value, massFactors());
      case POWER:
        return convert(value, UnitFactorSets.POWER);
      case PRESSURE:
        return convert(value, Unit.MILLIBAR);
      case SPEED:
        return convert(value, speedUnit());
      case TEMPERATURE:
        return convert(value, temperatureUnit());
      case VOLUME:
        return convert(value, volumeFactors());
    }
    
    return value;
  }
466600
def get_base_equivalent(self, unit_system=None):
        
        from unyt.unit_registry import _sanitize_unit_system

        unit_system = _sanitize_unit_system(unit_system, self)
        try:
            conv_data = _check_em_conversion(
                self.units, registry=self.registry, unit_system=unit_system
            )
        except MKSCGSConversionError:
            raise UnitsNotReducible(self.units, unit_system)
        if any(conv_data):
            new_units, _ = _em_conversion(self, conv_data, unit_system=unit_system)
        else:
            try:
                new_units = unit_system[self.dimensions]
            except MissingMKSCurrent:
                raise UnitsNotReducible(self.units, unit_system)
        return Unit(new_units, registry=self.registry)
475836
def unit_value(self, value):
        

        if isinstance(value, TimeUnit):
            self._unit = value
        else:
            self._unit = TimeUnit(value)
1348199
def convert(b):
    '''
    
    '''
    if b > 1024**3:
        hr = round(b/1024**3)
        unit = "GB"
    elif b > 1024**2:
        hr = round(b/1024**2)
        unit = "MB"
    else:
        hr = round(b/1024)
        unit = "KB"
    return hr, unit
160861
function ms (val) {
  if (!val || typeof val === 'number') {
    return val
  }

  const [ num, unit ] = parseUnit(val)

  if (unit === 'ms') {
    return num
  } else if (unit === 's') {
    return num * 1000
  } else {
    return num
  }
}
604514
def _convert_units(devices):
    '''
    
    '''
    if devices:
        for device in devices:
            if 'unit' in device and 'size' in device:
                device.update(
                    salt.utils.vmware.convert_to_kb(device['unit'], device['size']))
    else:
        return False
    return True
1297249
def unit(self, unit):
        
        allowed_values = ["cm", "inch", "foot"]  # noqa: E501
        if unit is not None and unit not in allowed_values:
            raise ValueError(
                "Invalid value for `unit` ({0}), must be one of {1}"  # noqa: E501
                .format(unit, allowed_values)
            )

        self._unit = unit
54061
def interpolate_at_i(self, i, unit=None):
        
        if isinstance(self.call.i._value, float):
            if self.call.i._value==i:
                return self._to_unit(self._value, unit)
            else:
                return None

        # we can't call i._value here because that may point to a string, and
        # we want this to resolve the array
        i_value = self.call.i.get_value(linebreak=False, sort_by_indep=False)
        if len(i_value) != len(self._value):
            raise ValueError("length mismatch with independent-variable")

        sort_inds = i_value.argsort()
        indep_value = i_value[sort_inds]
        this_value = self._value[sort_inds]
        return self._to_unit(np.interp(i, indep_value, this_value, left=np.nan, right=np.nan), unit)
1273772
def to_inches(value, units):
    
    lookup = {'in': lambda x: x,
              'cm': lambda x: x/2.54,
              'mm': lambda x: x/(2.54*10)}
    try:
        return lookup[units](value)
    except KeyError:
        raise PlotnineError("Unknown units '{}'".format(units))
927829
private static Object convert(Class<?> clazz, String value) {
      /* TODO create a new Converter class and move this method there for reuse */

        if (Integer.class.equals(clazz) || int.class.equals(clazz)) {
            return Integer.valueOf(value);
        } else if (Double.class.equals(clazz) || double.class.equals(clazz)) {
            return Double.valueOf(value);
        } else if (Long.class.equals(clazz) || long.class.equals(clazz)) {
            return Long.valueOf(value);
        } else if (Boolean.class.equals(clazz) || boolean.class.equals(clazz)) {
            return Boolean.valueOf(value);
        }

        return value;
    }
353141
def convert_to_equivalent_unit!(new_unit)
      old_unit = @unit
      self.multiply!(Unit.ratio new_unit, old_unit)
      old_base_units = old_unit.base_units.map { |base| base.unit } if old_unit.is_compound_unit?
      self.cancel_base_units!(*old_base_units || [old_unit])
    end
1203087
def to_si(self, values, from_unit):
        """"""
        if from_unit in self._si_units:
            return values, from_unit
        elif from_unit == 'degF-hours':
            return self.to_unit(values, 'degC-hours', from_unit), 'degC-hours'
        else:
            return self.to_unit(values, 'degC-days', from_unit), 'degC-days'
558557
def convert_scale(quantity)
      if Quantity===quantity
        assert_same_dimension(quantity.unit)
        v = quantity.value * quantity.unit.conversion_factor
        v = v / self.conversion_factor
      else
        quantity / to_numeric
      end
    end
1325531
def to_unit(self, unit):
        """"""
        new_data_c = self.duplicate()
        new_data_c.convert_to_unit(unit)
        return new_data_c
401640
def _normalize_to_unit(self, value, unit):
        
        if unit == 'ms':
            return value / 1000.0
        if unit == 'us':
            return value / 1000000.0
        if unit == 'KB':
            return value * 1024
        if unit == 'MB':
            return value * 1024 * 1024
        if unit == 'GB':
            return value * 1024 * 1024 * 1024
        if unit == 'TB':
            return value * 1024 * 1024 * 1024 * 1024

        return value
890722
def display_unit(self):
        
        if self._display_unit:
            return self._display_unit
        elif self._Q:
            config = Configuration.display.unit_systems
            default_system = Configuration.unit_system
            units = config.systems[default_system]

            self._display_unit = units.get(self._type, self._unit)

            if self._type == "temperature":
                from_unit = "deg" + self._unit.upper()
                to_unit = "deg" + self._display_unit.upper()
            else:
                from_unit = self._unit
                to_unit = self._display_unit

            #print("dv", from_unit, to_unit)
            self._q_unit = self._Q("1 " + from_unit)
            self._q_display = self._Q("1 " + to_unit)
            
            
        return self._display_unit
135126
def to_seconds(value, time_unit):
        
        if isinstance(value, bool):
            # bool is a subclass of int. Don't let bool and float multiplication.
            raise TypeError
        return float(value) * time_unit