casting

How do I convert a string to a number in PHP?

大城市里の小女人 提交于 2019-12-16 23:15:28
问题 I want to convert these types of values, '3' , '2.34' , '0.234343' , etc. to a number. In JavaScript we can use Number() , but is there any similar method available in PHP? Input Output '2' 2 '2.34' 2.34 '0.3454545' 0.3454545 回答1: You don't typically need to do this, since PHP will coerce the type for you in most circumstances. For situations where you do want to explicitly convert the type, cast it: $num = "3.14"; $int = (int)$num; $float = (float)$num; 回答2: There are a few ways to do so:

Implicit type conversion rules in C++ operators

早过忘川 提交于 2019-12-16 19:04:36
问题 I want to be better about knowing when I should cast. What are the implicit type conversion rules in C++ when adding, multiplying, etc. For example, int + float = ? int * float = ? float * int = ? int / float = ? float / int = ? int / int = ? int ^ float = ? et cetera... Will the expression always be evaluated as the more precise type? Do the rules differ for Java? Please correct me if I have worded this question inaccurately. 回答1: In C++ operators (for POD types) always act on objects of the

Casting a loaded SWF as an interface

南楼画角 提交于 2019-12-14 04:22:45
问题 I'm trying to load in a remote SWF and access it's methods and properties, using an interface. (There's a similar question here that got as far as "that's weird!" but didn't resolve it: Loading swf and using it through interface) My remote SWF looks like this: package { import flash.display.Sprite; import flash.events.Event; import flash.system.Security; import IMultiplayer; [SWF(width="238", height="60", frameRate="60", backgroundColor="#FFFFFF")] public class Main extends Sprite implements

Haxe abstracts - Can I implicitly cast an array when using @:from?

旧街凉风 提交于 2019-12-14 03:54:30
问题 I'm attempting to treat an array of one type as an array of another (abstract) type. It works fine when I use the underlying type of the abstract. But when I attempt implicit conversion using another type (defined using @:from keyword), I get a build failure. It works if I use an explicit cast , but I'm wondering - is there any way around this / something I'm missing? In the example below, I get the build failure Array<Int> should be Array<StringAbstract> class Test { static function main() {

Unable to cast C#

别等时光非礼了梦想. 提交于 2019-12-14 03:49:41
问题 I have 2 different projects in my solution. In one I have a class called MyClass1, and in the other I have MyClass2 These classes are identical in all but name. In one project I have a list of Objects. During runtime the list gets filled with MyClass1 objects that we casted to an object. At the end I want to cast each object in the list to a MyClass2 object. Currently it throws an exception saying Unable to cast object of type MyClass1 to MyClass2. My Code: List<Object> _tempObjects = new

String casts in .NET

故事扮演 提交于 2019-12-14 03:39:41
问题 Why is there so may ways to convert to a string in .net? The ways I have seen are .ToString, Convert.ToString() and (string). What is the Difference. 回答1: Convert.ToString(obj) Converts the specified value to its equivalent String representation. Will return String.Empty if specified value is null . obj.ToString() Returns a String that represents the current Object. This method returns a human-readable string that is culture-sensitive. For example, for an instance of the Double class whose

c++ - malloc casting error

我怕爱的太早我们不能终老 提交于 2019-12-14 03:36:06
问题 Everyones suggesting not to cast while allocating a pointer here, do I cast result of malloc But my below non-casted code produce compiler error in VS-2013. Why! #include <stdio.h> #include <malloc.h> int main(){ int *ptr = malloc(sizeof(int) * 100); // compiler error return 0; } Compiler error is, 1 IntelliSense: a value of type "void *" cannot be used to initialize an entity of type "int *" 回答1: The advice in the other question is strictly for C only. In C++ , you need the cast, since C++

Error in Veins tutorial simulation

◇◆丶佛笑我妖孽 提交于 2019-12-14 03:28:36
问题 I am starting to use Omnet++ with veins for VANET simulations, but at the end of the tutorial (http://veins.car2x.org/tutorial/), where it says to go into the IDE and click "Run As > OMNeT++ simulation", an error occured : Cannot evaluate parameter 'headerLength': (omnetpp::cDoubleParImpl)headerLength: Cannot cast from type double to integer - in module (Mac1609_4) RSUEXAMPLESCENARIO.rsu[0].nic.mac1609_4 (id=12), during network initialization. Ok, it crash trying to cast int from double, but

AS3: How to implement instanceOf with classes?

∥☆過路亽.° 提交于 2019-12-14 03:18:13
问题 I want to implement this method function isInstance(a:Class, b:Class):Boolean; This is how AS3 work with Classes. Note that MovieClip extends Sprite. trace(MovieClip is Sprite); // false trace(Sprite is MovieClip); // false trace(Sprite is Sprite); // false trace(Sprite is Object); // true I been trying the next code but it is not working: /** * return if instance of class 'a' can be cast to instant of class 'b' */ private function isInstance(a:Class, b:Class):Boolean{ var superclass:Class =

Casting generic type with interface constraint

佐手、 提交于 2019-12-14 03:15:16
问题 I have the following classes and interfaces public interface IFoo {} public class Foo : IFoo {} public interface IWrapper<T> where T : IFoo {} public class Wrapper<Foo> : IWrapper<Foo> {} How can I cast Wrapper<Foo> to IWrapper<IFoo> ? An exception is raised when using Cast (InvalidCastException) as I get null when using as. Thanks for the help! UPDATE Here is a more concrete example: public interface IUser {} public class User : IUser {} public interface IUserRepository<T> where T : IUser {}