type-casting

PHP: Why typecast with !!$var instead of (boolean)$var?

Both of these will ensure than $var is a boolean value, but the latter seems more clear. The double exclamation mark (!!) is shorter to type but less clear, and more likely to cause confusion. Not to mention hard to run a search on to get answers. The double exclamation mark is something I've only heard of in JavaScript, which doesn't...

Why does ConvertTo work, but casting fail in some cases?

I was always curious. Why does this work: double Number = Convert.ToDouble(TextBox1.Text); But this doesn't: double Number = (double)TextBox1.Text; ...

float is getting mangled when passing between methods (typecasting problem?)

I'm having trouble passing a float value from one object to another. It appears to be fine in the first method, but in the second its value is huge. I assume this is some kind of a problem with my typecasting, because that's the thing I understand the poorest. Help is greatly appreciated! In my game controller, I do this: float accurac...

PHP typecasting float->int

Given this PHP code: // total is 71.24 (float) $value = $total * 100; var_dump($value); $valuecast = (int)$value; var_dump($valuecast); settype($value, 'int'); var_dump($value); var_dump($value) gives float(7124) var_dump($valuecast) gives int(7123) var_dump($value) after settype gives int(7123) How can I get the correct type conve...

How to get (/ 7 2 ) => 3, do I need some sort of typecast?

When I do (/ 7 2), what should I do to get the result 3? If I do (/ 7 2.0), I get 3.5, which is as expected. ...

I want "(int)null" to return me 0.

How can i get 0 as integer value from (int)null. EDIT 1: I want to create a function that will return me default values for null representation in their respective datatypes. EDIT 2: How can i work in this scenario for using default. (int)Value Where Value can be null or any integer value. I dont know datatype of value at run time. B...

determine the type of a value which is represented as string in python

When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below. import csv a = "1,2,3,4,5" r = csv.reader([a]) for row in r: d = row d ['1', '2', '3', '4', '5'] type(d[0]) <type 'str'> I want to determine for each value if it is a string, float, integer or date....

C# Type-casting oddity - interface as the generic type

I've just run into what I think is an oddity in type-casting. I have code similar to the following: interface IMyClass { } class MyClass: IMyClass { } class Main { void DoSomething(ICollection<IMyClass> theParameter) { } HashSet<MyClass> FillMyClassSet() { //Do stuff } void Main() { HashSet<MyClass> classSet = Fi...

Creating a Win32 Window app with English title bar, but the title bar becomes Chinese out of nowhere. How come?

HWND wndHandle; //global variable // code snipped WNDCLASSEX wcex; // code snipped wcex.lpszClassName = (LPCWSTR) "MyTitleName"; // code snipped wndHandle = CreateWindow( (LPCWSTR)"MyTitleName", //the window class to use (LPCWSTR)"MyTitleName", //the title bar text ... ... I am following a tutoria...

Java: Dynamic type casting using enums

Hi, I am trying to do something along the lines of: public void setContents(Object[] values) { ... //A. this works mRank = ((String)(values[Columns.RANK.index])); //B. doesn't work (entire line underlined by netbeans) mRank = (Columns.RANK.type.cast(values[Columns.RANK.inde...

Why does a SelectionKey registered to a DatagramChannel return a SelectableChannel in Scala but not Java?

I am converting some Java NIO code to run in Scala and I am getting an error because the SelectionKey I'm calling returns a SelectableChannel rather than a DatagramChannel, which is a subclass of SelectableChannel and an instance of which I declare at the beginning of the code. I did not come to Scala from Java, so my knowledge of Java i...

Does Java casting introduce overhead? Why?

Is there any overhead when we cast objects of one type to another? Or the compiler just resolves everything and there is no cost at run time? Is this a general things, or there are different cases? For example, suppose we have an array of Object[], where each element might have a different type. But we always know for sure that, say, e...

C# All math operations return as an integer?

Possible Duplicate: byte + byte = int why? I have a grid from (-1024,-1024) to (1024,1024), so I don't need all the values that an int provides, but I've noticed that all of my algorithms return as ints and I need to typecast them all with (short). Could anyone explain why all math operations return as int and is it more effec...

String was not recognized as a valid DateTime " format dd/MM/yyyy"

I am trying to convert my string formated value to date type with format dd/MM/yyyy. this.Text="22/11/2009"; DateTime date = DateTime.Parse(this.Text); What is the problem ? It has a second override which asks for IFormatProvider. What is this ? DO I need to pass this also. If Yes how to use it for this case Edit What is t...

Trying to parse String to DateTime into format "02/01/2010" dd/MM/yyyy rather than "1/2/2010 MM/dd/yyyy

I am trying to convert a string into date time format. DateTime.Parse(tempfrmBankDetails.dgvBankDetails.SelectedRows[0].Cells["PaymentDate"].Value.ToString(),null); This is printed as an output but i want it in dd/MM/yyyy format. How should i parse it {1/2/2010 12:00:00 AM} EDIT I have created a custom control which accepts s...

Dynamically create PHP object based on string

I would like to create an object in PHP based on a type defined by a string in a MySQL database. The database table has columns and sample data of: id || type || propertyVal  1 || foo    || lorum  2 || bar    || ipsum ...with PHP data types class ParentClass {...} class Foo extends ParentClass {private $id, $propertyVal; ...} class Ba...

Unsafe cast in delphi sometimes gives a nil only on certain machines?

We have some code something like this (Delphi 6 RTL Update Pack 3): objChild1 := TChild1.create(); ... (Some Code) objProcessor.function1(objChild1); Tchild1 is inherited from TGrandPa through 2 + hierarchy levels. function1 is defined like this where objChildData is a private variable of TProcessor class and is of type TChild1 : TP...

Converting __int64 to long in Windows

How to convert __int64 to long in Windows (MSVC8 & MSVC6)? Will a normal typecasting work? Also, how about converting long to __int64? If the long is a negative value, will it work? Note - I am talking of a scenario in which the __int64 variable will always contain a value which will not be more than 32 bits long. ...

Memory use when casting? [C]

This is more of a theory question, then any actual code. I understand that if you declare a variable int i; then it sets aside 4 bytes in memory for the integer i. I understand if you use malloc to create your memory as well. I am curious how memory is handled when you do something like int x; int y; double z; z = (float)x/(float)y; ...

SubSonic 3.0 exception "'Public member 'ChangeTypeTo' on type 'Decimal' not found."

When saving a row that has an integer primary key following exception is thrown in the VB version: 'Public member 'ChangeTypeTo' on type 'Decimal' not found.' This happens in ActiveRecord.VB file : Public Sub SetKeyValue(value As Object) Implements IActiveRecord.SetKeyValue If value IsNot Nothing AndAlso value IsNot DBNull.Value T...