type-conversion

Javascript: Cast Math.sqrt to int?

I've searched through google (maybe I didn't look hard enough) but I could not find how to turn Math.sqrt into an int. I want to use Math.sqrt for a for loop and I guess I need it as an int but I can't seem to figure out how to cast the result to an int. So how do I do it? I tried something similar to Java: (int) Math.sqrt(num); Bu...

*Subtle* Differences between VB functions and Convert.To* functions?

While converting types, I have found myself using both VB functions and BCL Convert.To* methods. E.g.) Cstr() vs. Convert.ToString() CInt() vs. Convert.ToInt32() CDbl() vs. Convert.ToInt64() etc... Are there any subtle differences that should be noted? ...

c++ unable to find operator via implicit conversion?

When writing a class to act as a wrapper around a heap-allocated object, I encountered a problem with implicit type conversion that can be reduced to this simple example. In the code below the wrapper class manages a heap-allocated object and implicitly converts to a reference to that object. This allows the wrapper object to be passed ...

How to cast from bool to void*?

I'm trying to build cairomm for gtkmm on windows using mingw. Compilation breaks at a function call which has a parameter which does a reinterpret_cast of a bool to a void*. cairo_font_face_set_user_data(cobj(), &USER_DATA_KEY_DEFAULT_TEXT_TO_GLYPHS, reinterpret_cast<void*>(true), NULL); This is where the code breaks, and reason is "i...

C# unsafe value type array to byte array conversions

I use an extension method to convert float arrays into byte arrays: public static unsafe byte[] ToByteArray(this float[] floatArray, int count) { int arrayLength = floatArray.Length > count ? count : floatArray.Length; byte[] byteArray = new byte[4 * arrayLength]; fixed (float* floatPointer = floatArray) { fixed ...

Python Reflection and Type Conversion

In Python, functions like str(), int(), float(), etc. are generally used to perform type conversions. However, these require you to know at development time what type you want to convert to. A subproblem of some Python code I'm trying to write is as follows: Given two variables, foo and bar, find the type of foo. (It is not known at ...

Character to Integer in C

Is there a way to convert a character to an integer in C? for example, '5' -> 5 thanks. ...

This object is an integral type. Can I get its value in fewer than five lines of code?

I have a data reader. I want to compare the value in it with the value 42. I know it is an integral type (e.g., what MySQL calls INT, TINYINT, SMALLINT, MEDIUMINT, BIGINT, JUMBODELUXEINT, etc.). I do not want to hardwire the actual type in to the C# code. The best I have come up with is object x = reader.GetValue(i); uint k = x is byte ...

Change column type from ntext to varbinary(max)

I have a table that has ntext field. MSDN says that ntext is deprecated and they suggest other data types: ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), var...

Why do I need to convert console input to a specific data type?

Looking for more help on converting to doubles, integers, and decimal format when doing calculations. EX: ...Console.Write(" INPUT TOTAL SALES : "); ...userInput = Console.ReadLine(); ...totalSales = Convert.ToDouble(userInput); I'm not completely understanding why I needed to convert such to a double, why it couldn't just be C...

Confused on C# Array of objects and implicit type conversion

I am trying to pass an array of a simple object to a web service and I'm really stuck on this error during compile of my web client project: Cannot implicitly convert type 'TRIMBrokerUtil.MetaData[]' to 'TRIMBrokerASMXProxy.ASMXProxy.MetaData[]' Here is my "utility" project compiled into TRIMBrokerUtil.dll: namespace TRIMBrokerUtil { ...

Convert int64_t to double

int64_t a = 1234; double d = (double) a; Is this the recommended way? ...

.NET Why can a string[] be passed as IEnumerable<string> parameter?

This is valid code: void func(IEnumerable<string> strings){ foreach(string s in strings){ Console.WriteLine(s); } } string[] ss = new string[]{"asdf", "fdsa"}; func(ss); What I want to know is, how does the implicit conversion string[] -> IEnumerable<string> work? ...

How can I convert a character to a integer in Python, and viceversa?

I want to get, given a character, its ascii value. For example, for the character 'a', I want to get 97, and viceversa. Thanks, Manuel ...

How to convert NSData to byte array in iPhone?

I want to convert NSData to a byte array, so I write the following code: NSData *data = [NSData dataWithContentsOfFile:filePath]; int len = [data length]; Byte byteData[len]; byteData = [data bytes]; But the last line of code pops up an error saying "incompatible types in assignment". What is the correct way to convert the data to by...

Can a C# delegate use the object type to be more generic?

I would like to create a delegate and a method that can be used to call any number of Web services that my application requires: Example: public DateCheckResponseGetDate(DateCheckRequest requestParameters) { delegate object WebMethodToCall(object methodObject); WebMethodToCall getTheDate = new WebMethodToCall(WebServices.GetTh...

Checking if a string can be converted to float in Python

I've got some Python code that runs through a list of strings and converts them to integers or floating point numbers if possible. Doing this for integers is pretty easy if element.isdigit(): newelement=int(element) Floating point numbers are more difficult. Right now I'm using partition('.') to split the string and checking to ...

Field Names for Struts2 map entries in a JSP

I want to populate a map property on a Struts2 action from a JSP. What is the format of the data names that I should use? Initially I am interested in populating a Map<String, String> but in the future I would be interesting in populating a Map<String, DomainClass> where the DomainClass has properties of its own. ...

Cannot implicitly convert type 'X' to 'string' - when and how it decides that it "cannot"?

Right now I'm having it with Guids. I certainly remember thah throughout the code in some places this implicit conversion works, in other does not. Until now I fail to see the pattern. How the compiler decides that it cannot? I mean, the type method Guid.ToString() is present, isn't it called whenever this transformation is needed? Ca...

Why is the result of this explicit cast different from the implicit one?

Why is the result of this explicit cast different from the implicit one? #include <stdio.h> double a; double b; double c; long d; double e; int main() { a = 1.0; b = 2.0; c = .1; d = (b - a + c) / c; printf("%li\n", d); // 10 e = (b - a + c) / c; d = (long) e; printf("%li\n", d); ...