Converts a value to a specified type.