Questions tagged [casting]

Casting is a process where an object type is explicitly converted into another type if the conversion is allowed. This process might lead to a change in value.

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

Passing value to function throws PSInvalidCastException [duplicate]

I've been dealing with this for the better part of two days and I just don't understand where the exception is coming from. I wrote a simple function to check if an integer is in a given range: ...
Arcturus's user avatar
  • 252
0 votes
2 answers
34 views

Converting an input to float

i am making a project that takes the input of something from an element, then provides all the necessary information back. For example, carbon can be identified by C, 12.011, or 6. The program i am ...
Ian Schaak's user avatar
0 votes
0 answers
52 views

Getting the reference for BufferedImage to and int[] problem

So i've read the other posts on this topic but they doesn't help me, only suggests that you should use byte[] instead. The problem is that im getting the exception: Exception in thread "main"...
Cworm's user avatar
  • 1
1 vote
2 answers
90 views

Mixed type arithmetics and overflow in C

I have a function which converts counter value using a factor and returns the result as unsigned long. I need to handle possible overflow. IntVars.Counter_ui32: unsigned long with range 2^32 and max ...
Hi.'s user avatar
  • 23
2 votes
1 answer
79 views

Is this cast of void pointer valid code or vile code?

Is this valid/proper code, or does it violate standards -- possibly invoking undefined behavior (UB)? --> Specifically, the cast of void * to char ** in foo(). <-- It does work, but we know ...
greg spears's user avatar
-2 votes
0 answers
41 views

One column is a string type the other is an integer type, how to inner join? [closed]

SELECT station_id, name, number_of_rides AS number_of_rides_starting_at_station FROM ( SELECT start_station_id, COUNT (*) number_of_rides FROM bigquery-...
Diana Thorson's user avatar
1 vote
0 answers
48 views

Casting in Zig (like usize to i32 and more)

As in other higher then asm level languages like Java, i want to cast values, compare it and more. For example filling array like this: var array: [10]i32 = undefined; for (0..array.len) |i| ...
varikoz272's user avatar
-3 votes
1 answer
92 views

Converting data types in SQL Server using CAST

I'm new to SQL Server and I would like to know how to convert data types in SQL Server. As far as I know SQL Server doesn't support format mask (ex.'YYYY-MM-DD' or '999'). It's basically about all ...
drk's user avatar
  • 41
0 votes
1 answer
50 views

avoid casting with different game types [closed]

Hey i am building a framework for the creation of reel games, but in my framwork different game types can be added, not only reelgames. For example, the main game is a reel game and the bonus game is ...
Amnesia584's user avatar
1 vote
1 answer
43 views

How to Cast From Object to My Class in Java

I'm Playing around with maps and i did this Map<String, Map<String, Object>> maps = new HashMap<>(); User user = new User("name", "age"); Profile profile = new ...
Ayman Subbagh's user avatar
2 votes
2 answers
93 views

In .NET, I get a weird "System.InvalidCastException: 'Unable to cast object of type 'System.Int32' to type 'System.Double'."

Houston, I have a problem. We all know that casting from any int to a double is implicit. But I have this weird case where it is not. Check this out, in a console project: static void Main(string[] ...
Albert Zakhia's user avatar
0 votes
0 answers
4 views

How to keep the windows casting ( WinKey + K) always open in the background so whenever i am using my tablet - I can connect right from the tablet

So currently I have to press (Win+K) keys to open the casting window and then it finds my tablet (where i select the second screen option) and both connect this way. I would like the windows part to ...
user8252485's user avatar
0 votes
2 answers
30 views

Convert Varchar2 into time

I want to convert a column from VARCHAR2 into a time related data type. For example, from 153312 into 15:33:12 I tried with to_timestamp(column, 'hh24:mi:ss') as time_column , but it gives me as a ...
Textime's user avatar
  • 99
-1 votes
0 answers
80 views

When using C++ in XCode, static casting an integer to a char gives me a \300 in the terminal

Using the line of C++ code below, C++ in XCode results in displaying a "\300" while it displays the proper Extended ASCII character (see this table https://www.asciitable.com/) on other ...
Rob's user avatar
  • 1
0 votes
0 answers
16 views

Type mismatch when importing from Pandas to SQLAlchemy Declarative Class

The code actually works but big red flag as pyright detects a type mismatch. When I import from a csv file to a Pandas dataframe and then instantiate company = Company(name=df['name'][index], ...
dkhokhar's user avatar
1 vote
1 answer
123 views

What is the fastest way to map numpy array of unsigned integer {0,1} to float {1,-1}

I have a numpy array of np.uint64 holding only 0 or 1 values, and I have to map 0 to np.float64(1.0), and 1 to np.float64(-1.0). Since the interpreter doesn't knows that it has only to convert 0 and 1,...
tutizeri's user avatar
  • 539
-3 votes
2 answers
75 views

Go, cannot convert type *int32 to type *int64 [duplicate]

I've tried all the ways I can think of to convert type *int32 to type *int64 in Go, but no avail https://go.dev/play/p/W2X0HEnn79q Somebody help please.
xpt's user avatar
  • 21.2k
0 votes
1 answer
32 views

Is it possible to make a Laravel Eloquent Cast that returns a comma decimal in the echo and a dot decimal in the mathematical operation?

I have a big problem! ;) A have a database data with decimal values (1.1, 1.19, 2, ...) I'm trying to make a Eloquent Cast Class that works on two different context: Return a comma decimal when it's ...
Ivan Nack's user avatar
  • 219
0 votes
1 answer
72 views

Issue setting entire column (and changing dtype) with .loc[:,'col'] in pandas 1.5+

I often use df.loc[:,'col'] = arr to reassign columns rather than df['col'] = arr. This was a recommended practice to avoid the fact that, prior to Copy-on-Write changes in pandas 2.0, we couldn't ...
nogaem's user avatar
  • 1
0 votes
0 answers
34 views

Why is the conditional operator in java behaving diffrently with conversions? I want to print float as integer form if the decimal part is 0 [duplicate]

I wanted to make a type of formatted printing (without using the printf() method) so that I can print a float varible without decimal point if the number does not contain a decimal part. I chose to ...
Kristi Teneqexhi's user avatar
1 vote
1 answer
39 views

Object List can't be null and I can't use cast because it's null in Flutter

I'm trying to pass a List in a loop to retrieve the strings and show them in a button, and this is happening: final List<Map<String, Object>> perguntas = [ { 'texto': '...
Raphael Wesley's user avatar
0 votes
0 answers
15 views

Googles Protobuf without deserialization

Normally google protobuf or the nanopb implementation is intended to serialize/deserialize messages on the server respectively the client side. However, I'm faced with a case where the serialization ...
Wör Du Schnaffzig's user avatar
-2 votes
0 answers
28 views

how do I cast a python variable to a c one properly pybind11?

I was trying to use the attached code to create a dll extension, however, the test(), function that can be seen, would not return a double. namespace py = pybind11; using namespace std; #define GMDLL ...
all-stairs's user avatar
2 votes
2 answers
182 views

Can I cast a number into an enum, safely, with a fallback value?

I would like to write something like: template <typename E, E fallback> E safe_cast_to_enum(std::underlying_type_t<E> e); which, for an enum class (or just an enum?) E, casts e to a ...
einpoklum's user avatar
  • 121k
-2 votes
1 answer
104 views

Trying to convert a column in SQL to simple duration (Column is like "3 Days 18 Hours 51 Minutes") [closed]

I have a column in SQL that has several fields in the format of "3 Days 18 Hours 51 Minutes." I was hoping someone could help change that duration into a plain number field like 5451 as the ...
mir4ge's user avatar
  • 1
-1 votes
1 answer
45 views

Is type conversion having a covariance error?

I'm learning how to build a compiler through a YouTube video, and there's a part where there's a type conversion error, in the locals.Add(parameter, value); section there's this error from Visual ...
Vagner Wentz's user avatar
0 votes
0 answers
6 views

Replace does not exist hint: you may need to add the explicit type casts,getting this error in rsql

How can I apply the casting to replace function? I am getting errors while casting the replace function. Select coalesce(replace(upper(problm_id),X'0d',''),X'0a',''),'N/A') FROM suv_prblm_f_v I have ...
Nikki's user avatar
  • 1
0 votes
3 answers
94 views

Primitive Integert Datatype Limits in Java

I have a Java programt o display the limits of primitive integer datatypes which is as follows: import static java.lang.Math.*; class HelloWorld { public static void main(String[] args) { ...
vidyapu sandeep's user avatar
0 votes
0 answers
16 views

Using Open3D detect_planar_patches (or similar) for mould part derivation

I have a complex model (eg the Stanford Dragon) from which I want to derive a multipart (by multipart, I mean maybe 8 or more parts) mould (us.english = mold - I'm going to use 'mould' here, though) ...
Konchog's user avatar
  • 1,942
0 votes
0 answers
50 views

How to cast Rc<RefCell<Box<SomeType>>> to Rc<Box<SomeType>>?

I have a function that accepts an argument of Rc<Box<SomeType>> type and a variable of Rc<RefCell<Box<SomeType>>> type, and I can't get how to pass my variable into this ...
Denis Steinman's user avatar
0 votes
0 answers
13 views

Is really SAFE_CAST is helpful to clear errors?

If CAST function fails it returns an error in BigQuery. To avoid any error we use SAFE_CAST. My question is that SAFE_CAST hide the error of SQL queries.Using, SELECT SAFE_CAST(MyDate AS STRING)FROM ...
Ramya's user avatar
  • 1
-1 votes
1 answer
33 views

Extract Date from a comment string

Greetings SQL Community, I am wondering what the best way is to extract the date and year from the following string structure: Example: 01/01/2023: This is the comment which can vary in length I am ...
GreyFox9881's user avatar
0 votes
1 answer
43 views

PostgreSQL how to cast multiple values

I have a PostgreSQL DB with a primary key column that is of type character varying length 32. The keys should be a 19 digit integer, e.g. 1234567891234567891 I want to do a simple query on the PK ...
sushi's user avatar
  • 306
0 votes
1 answer
53 views

Why does one method of adding all the elements of an array fail when similar methods succeed [closed]

I have an array of doubles. To simplify the example, I use an array of length 3. I want to add all 3 elements of the array. I do it in 3 ways. Here's the program to demonstrate. #include <stdio.h&...
rkg125's user avatar
  • 41
1 vote
2 answers
64 views

Java : casting and generics

I have some understanding issue with generics I have this variable : private static final UnaryOperator<Object> IDENTITY_FN = t -> t; I don't understand why this code compiles : public static ...
AntonBoarf's user avatar
  • 1,241
0 votes
2 answers
46 views

Render numbers inside an Ansible yaml template

Very close to Create an int var with Ansible's ternary operator and that answer https://stackoverflow.com/a/69109779/446302 In an Ansible project, I'm trying to have a yaml template file with ...
samb's user avatar
  • 1,733
3 votes
1 answer
89 views

auto ( expression ) in direct initialization argument

In C++23 we have explicit type convertion auto ( expression ), and according to cppreference it is already supported by both GCC and Clang. I have a question where such cast does not occur for some ...
Fedor's user avatar
  • 17.7k
0 votes
1 answer
21 views

Casting uint8_t* to int16_t8 in C

I am attempting to adapt an example from here which reads PDM microphone data and prints it to a computer using serial USB. I want to bypass the filtering stage in the example so I can write my own ...
jjjjbbb's user avatar
0 votes
2 answers
74 views

AWS Athena Query to convert complex string column to integer

I have an Athena table with a string column which looks like: +-------------------+ | employee_size | +-------------------+ | GREATER THAN 2000 | +-------------------+ | 500 - 999 | +------...
Siddarth Patil's user avatar
-2 votes
0 answers
36 views

Is it possible to implement some user-defined conversion operator for pointers? [duplicate]

I know that it's possible add implicit cast from T to U*, but I couldn't find any examples of how to allow implicit cast of T* to U*. Is it possible? I found this question, but it was 12 years ago ...
Michael Pacheco's user avatar
0 votes
2 answers
92 views

Encode a std::uint64_t into vector of floats

I have to do some dirty trickery and pass a std::uint64_t around an application. Unfortunately I am limited to using a std::vector<float> for that. To my understanding float is 32-bit on most ...
Foaly's user avatar
  • 577
1 vote
1 answer
96 views

How should I statically cast a std::shared_ptr of one type to a std::shared_ptr of another

My code is below. I want to convert std::shared_ptr<void> to std::shared_ptr<C>, but it didn't work. I got the following error: main.cpp:74:63: error: no matching function for call to ‘std:...
chunlin yang's user avatar
0 votes
1 answer
37 views

Casting problems when attempting to access pdf from Camunda cockpit variables to be sent as email in Java class

My goal here is to access an execution variable of type pdf that i uploaded earlier, then to send this pdf as an attachment in an email using a Java class referenced in a service task. Cockpit ...
b_a9f's user avatar
  • 9
-1 votes
2 answers
99 views

How to cast volatile typedef struct to non-volatile typedef struct as argument of the function

I'm writing a C library for STM32 and ran into a problem. I have typedef struct: typedef struct foo { // some struct elements } foo; Volatile variable with foo type: volatile foo bar; And ...
t1m013y's user avatar
0 votes
2 answers
97 views

Default argument promotions in C cause error,but I don't know exactly why

The following code example is from K. N. King's C Programming. A Modern Approach. It doesn't work properly: the output is 1 instead of 9. The author says that this is a problem caused by the default ...
ll cool's user avatar
  • 53
1 vote
1 answer
61 views

How to convert email address values into numbers?

Is there any way to convert email address values into numbers? Context: I have a list of EmailAddress in a table where I do not have IDs and I want to generate IDs from EmailAddress so I can use ...
kuml2's user avatar
  • 125
0 votes
1 answer
53 views

Assigning an Integer literal to a char data type in Java [duplicate]

While learning Java, I came across the statement - "You cannot assign an integer to a char data type directly without explicitly casting it" I tried the below example : char ch = 65; System....
Anshul V. Kumar's user avatar
0 votes
0 answers
31 views

Why variable cannot be used for casting datatype in Pyspark

I could not get why it behaves this way. I want to dynamically cast dataframe new column. but it throws error. where as if we directly mention, it is working. your input will help me to rectify my ...
RamK's user avatar
  • 11
0 votes
0 answers
62 views

Converting values inside nested stl containers

My whole point is that I have a struct S { double x, y; // some code defining properties and operations on such pairs. // ... // ... operator std::pair<double, double>(){ return {...
Bubaya's user avatar
  • 687
0 votes
0 answers
45 views

Casting a child class to a parent class seems to keep the object as the child class

I have two classes,Parent and Child. Instances myParent and myChild Child has a few more properties than the Parent. I need to remove these extra properties from a Child Instance by Casting it as a ...
user3844416's user avatar

1
2 3 4 5
397