Cast an individual value
966630
def cast_value(parent, value)
      if !allow_blank && value.to_s.empty?
        nil
      else
        value = typecast_value(parent, self, value)
        associate_casted_value_to_parent(parent, value)
      end
    end
1179740
def _cast(cls, base_info, take_ownership=True):
        

        type_value = base_info.type.value
        try:
            new_obj = cast(base_info, cls.__types[type_value])
        except KeyError:
            new_obj = base_info

        if take_ownership:
            assert not base_info.__owns
            new_obj._take_ownership()

        return new_obj
879242
def cast_value(value)
      return value if value.blank?
      return value if form_options.is_a? Proc
      return field_options[:cast].call(value) if field_options[:cast].is_a? Proc
      case form_options[:as]
        when :bs_datetimepicker
          if value.is_a? String
            DateTime.parse(value)
          elsif value.is_a? Date
            value.to_time
          else
            value
          end
        when :bs_datepicker
          if value.is_a? String
            DateTime.parse(value).to_date
          elsif value.is_a? DateTime
            value.to_date
          else
            value
          end
        else
          value
      end

    end
913946
public static <T> T cast(Object value, Class<T> type) {
        if (null == value) {
            return null;
        }
        if (!type.isAssignableFrom(value.getClass())) {
            if (is(type, int.class, Integer.class)) {
                value = Integer.parseInt(value.toString());
            } else if (is(type, long.class, Long.class)) {
                value = Long.parseLong(value.toString());
            } else if (is(type, float.class, Float.class)) {
                value = Float.parseFloat(value.toString());
            } else if (is(type, double.class, Double.class)) {
                value = Double.parseDouble(value.toString());
            } else if (is(type, boolean.class, Boolean.class)) {
                value = Boolean.parseBoolean(value.toString());
            } else if (is(type, String.class)) {
                value = value.toString();
            }
        }
        return (T) value;
    }
528001
def cast(
    source: Union[DataType, str], target: Union[DataType, str], **kwargs
) -> DataType:
    """"""
    source, result_target = dtype(source), dtype(target)

    if not castable(source, result_target, **kwargs):
        raise com.IbisTypeError(
            'Datatype {} cannot be implicitly '
            'casted to {}'.format(source, result_target)
        )
    return result_target
1014771
function cast(type, variable) {
		var result = variable;

		switch (type) {
			case 'number':
				result = +result;
				break;

			case 'int':
				result = parseInt(result, 10);
				break;

			case 'float':
				result = parseFloat(result);
				break;

			case 'bool':
			case 'boolean':
				result = ['true', '1', 1].indexOf(result) >= 0;
				break;
		}

		return result;
	}
103795
public static Object getCastingValue(ColumnType columnType, Object value) throws ExecutionException {
        validateInput(columnType);
        Object returnValue = null;
        if (value != null) {
            switch (columnType.getDataType()) {

                case BIGINT:
                    ensureNumber(value);
                    returnValue = ((Number) value).longValue();
                    break;
                case DOUBLE:
                    ensureNumber(value);
                    returnValue = ((Number) value).doubleValue();
                    break;
                case FLOAT:
                    ensureNumber(value);
                    returnValue = ((Number) value).floatValue();
                    break;
                case INT:
                    ensureNumber(value);
                    returnValue = ((Number) value).intValue();
                    break;
                default:
                    returnValue = value;

            }
        }

        return returnValue;
    }
852489
def cast_value(parent, value)
      raise "An array inside an array cannot be casted, use CastedModel" if value.is_a?(Array)
      value = typecast_value(value, self)
      associate_casted_value_to_parent(parent, value)
    end
354911
def cast_primitive(state, value, to_type):
        
        if to_type in ['float', 'double']:
            if value.symbolic:
                # TODO extend support for floating point types
                l.warning('No support for symbolic floating-point arguments.'
                          'Value gets concretized.')
            value = float(state.solver.eval(value))
            sort = FSORT_FLOAT if to_type == 'float' else FSORT_DOUBLE
            return FPV(value, sort)

        elif to_type == 'int' and isinstance(value, FP):
            # TODO fix fpToIEEEBV in claripty
            l.warning('Converting FP to BV might provide incorrect results.')
            return fpToIEEEBV(value)[63:32]

        elif to_type == 'long' and isinstance(value, FP):
            # TODO fix fpToIEEEBV in claripty
            l.warning('Converting FP to BV might provide incorrect results.')
            return fpToIEEEBV(value)

        else:
            # lookup the type size and extract value
            value_size = ArchSoot.sizeof[to_type]
            value_extracted = value.reversed.get_bytes(index=0, size=value_size//8).reversed

            # determine size of Soot bitvector and resize bitvector
            # Note: smaller types than int's are stored in a 32-bit BV
            value_soot_size = value_size if value_size >= 32 else 32
            if to_type in ['char', 'boolean']:
                # unsigned extend
                return value_extracted.zero_extend(value_soot_size-value_extracted.size())
            # signed extend
            return value_extracted.sign_extend(value_soot_size-value_extracted.size())
557315
function cast(string) {
	var result = String(string);
	switch (result) {
		case 'null':
			result = null;
			break;
		case 'true':
		case 'false':
			result = result === 'true';
			break;
		default:
			if (String(parseInt(result, 10)) === result) {
				result = parseInt(result, 10);
			} else if (String(parseFloat(result)) === result) {
				result = parseFloat(result);
			}
			break;
	}
	return result === '' ? true : result;
}
69181
def _cast_to_type(self, value):
        
        if isinstance(value, datetime.datetime):
            return value.date()
        if isinstance(value, datetime.date):
            return value
        try:
            value = date_parser(value)
            return value.date()
        except ValueError:
            self.fail('invalid', value=value)
310353
def cast(cls, c):
        """"""
        if isinstance(c, Complete):
            return c
        elif isinstance(c, Translation):
            return Complete(np.identity(3, float), c.t)
        elif isinstance(c, Rotation):
            return Complete(c.r, np.zeros(3, float))
567270
def _clean(self, value):
        """"""
        if value is None:
            return None
        elif self.type_ is None:
            return value
        elif self.check_type(value):
            return value
        elif self.is_type_castable:  # noqa
            return self.type_(value)

        error_fmt = "%s must be a %s, not a %s"
        error = error_fmt % (self.name, self.type_, type(value))
        raise TypeError(error)
634173
private static Object setIntValue(Field member, Object retVal)
    {
        if (member != null)
        {
            if (member.getType().isAssignableFrom(byte.class))
            {
                retVal = ((Integer) retVal).byteValue();
            }
            else if (member.getType().isAssignableFrom(short.class))
            {
                retVal = ((Integer) retVal).shortValue();
            }
        }
        return retVal;
    }
871112
def cast_type(self, var, cast_type=None):
        

        if cast_type is None:
            cast_type = self.valid_values

        try:
            if cast_type == int:
                return int(var)
            elif cast_type == float:
                return float(var)
            elif type == str:
                return str(var)
            elif isinstance(cast_type, list):
                # cast var to be of the same type as those in the list
                return type(cast_type[0])(var)
            else:
                return None
        except ValueError:
            return None

        return var
1001908
def _cast_number(value): # source: https://bitbucket.org/openpyxl/openpyxl/src/93604327bce7aac5e8270674579af76d390e09c0/openpyxl/cell/read_only.py?at=default&fileviewer=file-view-default
    ""
    m = FLOAT_REGEX.search(value)
    if m is not None:
        return float(value)
    return int(value)
1096521
def cast(self, topic, value):
        
        datatype_key = topic.meta.get('datatype', 'none')
        result = self._datatypes[datatype_key].cast(topic, value)
        validate_dt = topic.meta.get('validate', None)
        if validate_dt:
            result = self._datatypes[validate_dt].cast(topic, result)
        return result