by calling the corresponding cast-to-decimal function, similar to other JSON cast function.
14085
private static BigDecimal currentTokenAsJavaDecimal(JsonParser parser, int precision, int scale)
            throws IOException
    {
        BigDecimal result;
        switch (parser.getCurrentToken()) {
            case VALUE_NULL:
                return null;
            case VALUE_STRING:
            case FIELD_NAME:
                result = new BigDecimal(parser.getText());
                result = result.setScale(scale, HALF_UP);
                break;
            case VALUE_NUMBER_FLOAT:
            case VALUE_NUMBER_INT:
                result = parser.getDecimalValue();
                result = result.setScale(scale, HALF_UP);
                break;
            case VALUE_TRUE:
                result = BigDecimal.ONE.setScale(scale, HALF_UP);
                break;
            case VALUE_FALSE:
                result = BigDecimal.ZERO.setScale(scale, HALF_UP);
                break;
            default:
                throw new JsonCastException(format("Unexpected token when cast to DECIMAL(%s,%s): %s", precision, scale, parser.getText()));
        }

        if (result.precision() > precision) {
            // TODO: Should we use NUMERIC_VALUE_OUT_OF_RANGE instead?
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast input json to DECIMAL(%s,%s)", precision, scale));
        }
        return result;
    }
988275
def cast(source, target):
    """"""
    import ibis.expr.operations as ops  # TODO: don't use ops here

    if not castable(source, target):
        raise com.IbisTypeError('Source is not castable to target type!')

    # currently it prevents column -> scalar implicit castings
    # however the datatypes are matching
    op = source.op()
    if not isinstance(op, ops.Literal):
        raise com.IbisTypeError('Only able to implicitly cast literals!')

    out_type = target.type().scalar_type()
    return out_type(op)
74337
static
	private Float toFloat(Object value){

		if(value instanceof Float){
			return (Float)value;
		} else

		if(value instanceof Double){
			Number number = (Number)value;

			return toFloat(number.floatValue());
		} else

		if((value instanceof Long) || (value instanceof Integer) || (value instanceof Short) || (value instanceof Byte)){
			Number number = (Number)value;

			return toFloat(number.floatValue());
		} else

		if(value instanceof Boolean){
			Boolean flag = (Boolean)value;

			return (flag.booleanValue() ? Numbers.FLOAT_ONE : Numbers.FLOAT_ZERO);
		} else

		if((value instanceof DaysSinceDate) || (value instanceof SecondsSinceDate) || (value instanceof SecondsSinceMidnight)){
			Number number = (Number)value;

			return toFloat(number.floatValue());
		}

		throw new TypeCheckException(DataType.FLOAT, value);
	}
496892
def process_bind_param(self, value, dialect):
        """"""
        if value is not None:
            value = simplejson.dumps(value)
        return value
640382
function castToScalar(value, state) {
    if (state.rowNum === 1) {
      // Don't cast column names
      return value;
    } else {
      var hasDot = /\./;
      var leadingZero = /^0[0-9]/;
      var numberWithThousands = /^[1-9]\d?\d?(,\d\d\d)+(\.\d+)?$/;
      if (numberWithThousands.test(value)) {
        value = value.replace(/,/g, "");
      }
      if (isNaN(value)) {
        return value;
      }
      if (leadingZero.test(value)) {
        return value;
      }
      if (hasDot.test(value)) {
        return parseFloat(value);
      }
      var integer = parseInt(value, 10);
      if (isNaN(integer)) {
        return null;
      }
      return integer;
    }
  }
898014
def _decode(cls, value):
        """"""

        value = cls._DEC_RE.sub(lambda x: '%c' % int(x.group(1), 16), value)
        return json.loads(value)
833267
def write_json_double(num)
      @context.write(trans)
      # Normalize output of thrift::to_string for NaNs and Infinities
      special = false;
      if (num.nan?)
        special = true;
        val = @@kThriftNan;
      elsif (num.infinite?)
        special = true;
        val = @@kThriftInfinity;
        if (num < 0.0)
          val = @@kThriftNegativeInfinity;
        end
      else
        val = num.to_s
      end

      escapeNum = special || @context.escapeNum
      if (escapeNum)
        trans.write(@@kJSONStringDelimiter)
      end
      trans.write(val)
      if (escapeNum)
        trans.write(@@kJSONStringDelimiter)
      end
    end
65446
function toFloat ( object ) {
        var transformed =  {};

        $.map( object, function ( value, key ) {
            transformed[key] =  parseFloat( value );
        } );

        return transformed;
    }
185275
private void parseSupplementalCurrencyData(JsonObject root) {
    JsonObject fractions = resolve(root, "supplemental", "currencyData", "fractions");
    for (String code : objectKeys(fractions)) {
      CurrencyData data = getCurrencyData(code);
      JsonObject node = fractions.get(code).getAsJsonObject();
      data.digits = Integer.valueOf(string(node, "_digits"));
      // Note: _rounding = 0 for all currencies in the modern data set.
    }
  }
1037884
def float_to_decimal(f):
    
    n, d = f.as_integer_ratio()
    numerator, denominator = Decimal(n), Decimal(d)
    return DECIMAL_CONTEXT.divide(numerator, denominator)
155517
private JsonElement convertValue(String value, JsonObject dataType) {
    if (dataType == null || !dataType.has(TYPE)) {
      return new JsonPrimitive(value);
    }

    String type = dataType.get(TYPE).getAsString().toUpperCase();
    ValueType valueType = ValueType.valueOf(type);
    return valueType.convert(value);
  }
353069
def cast(self, value, custom_formatters=None, strict=True):
        """"""
        if value is None:
            if not self.nullable:
                raise InvalidSchemaValue("Null value for non-nullable schema", value, self.type)
            return self.default

        cast_mapping = self.get_cast_mapping(
            custom_formatters=custom_formatters, strict=strict)

        if self.type is not SchemaType.STRING and value == '':
            return None

        cast_callable = cast_mapping[self.type]
        try:
            return cast_callable(value)
        except ValueError:
            raise InvalidSchemaValue(
                "Failed to cast value {value} to type {type}", value, self.type)
148727
public static long castToIntegral(Decimal dec) {
		BigDecimal bd = dec.toBigDecimal();
		// rounding down. This is consistent with float=>int,
		// and consistent with SQLServer, Spark.
		bd = bd.setScale(0, RoundingMode.DOWN);
		return bd.longValue();
	}
296923
def to_f_with_decimal_places(s, p=1)
      unless s.nil?
        v = (s.to_f / (10 ** p))
        logger.debug "Casting #{s.inspect}  ->  #{v.inspect}"
        v
      else
        logger.error "Could not cast #{s} to #{p} decimal places"
      end
    end
573651
function castType(val, type, def) {
    function cast() {
        if (!is_1.isValue(val))
            return to_1.toDefault(null, def);
        // If no type specified try to get automatically.
        type = type || getType(val);
        if (is_1.isArray(type)) {
            return to_1.toArray(val)
                .map(function (v, i) { return castType(v, type[i] || type[i - 1] || type[0]); });
        }
        else if (is_1.isFunction(type)) {
            val = to_1.toArray(val);
            return type.apply(void 0, val);
        }
        else if (is_1.isString(type)) {
            type = type.toLowerCase();
            var func = toMap[type];
            if (func)
                return func(val);
            return to_1.toDefault(null, def);
        }
        else {
            return val;
        }
    }
    return function_1.tryWrap(cast)(def);
}
1318731
def _cast_to_type(self, value):
        
        if not isinstance(value, dict):
            self.fail('invalid', value=value)
        return value
805866
def _cast(self, value, format=None, **opts):
        """"""
        if format is not None:
            return datetime.strptime(value, format)
        return dateutil.parser.parse(value)