convert double to int

You can use a cast if you want the default truncate-towards-zero behaviour. Alternatively, you might want to use Math.Ceiling, Math.Round, Math.Floor etc – although you’ll still need a cast afterwards. Don’t forget that the range of int is much smaller than the range of double. A cast from double to int won’t throw an exception … Read more

Android: How can I Convert String to Date?

From String to Date String dtStart = “2010-10-15T09:27:37Z”; SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss’Z'”); try { Date date = format.parse(dtStart); System.out.println(date); } catch (ParseException e) { e.printStackTrace(); } From Date to String SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss’Z'”); try { Date date = new Date(); String dateTime = dateFormat.format(date); System.out.println(“Current Date Time : ” + dateTime); } … Read more

Any difference between type assertions and the newer `as` operator in TypeScript?

The difference is that as Circle works in TSX files, but <Circle> conflicts with JSX syntax. as was introduced for this reason. For example, the following code in a .tsx file: var circle = <Circle> createShape(“circle”); Will result in the following error: error TS17002: Expected corresponding JSX closing tag for ‘Circle’. However, as Circle will … Read more

How to check that a string is an int, but not a double, etc.?

How about using ctype_digit? From the manual: <?php $strings = array(‘1820.20’, ‘10002’, ‘wsl!12’); foreach ($strings as $testcase) { if (ctype_digit($testcase)) { echo “The string $testcase consists of all digits.\n”; } else { echo “The string $testcase does not consist of all digits.\n”; } } ?> The above example will output: The string 1820.20 does not … Read more

In Objective-C, what is the equivalent of Java’s “instanceof” keyword?

Try [myObject class] for returning the class of an object. You can make exact comparisons with: if ([myObject class] == [MyClass class]) but not by using directly MyClass identifier. Similarily, you can find if the object is of a subclass of your class with: if ([myObject isKindOfClass:[AnObject class]]) as suggested by Jon Skeet and zoul.

Downcasting in Java

Downcasting is allowed when there is a possibility that it succeeds at run time: Object o = getSomeObject(), String s = (String) o; // this is allowed because o could reference a String In some cases this will not succeed: Object o = new Object(); String s = (String) o; // this will fail at … Read more

Change type of varchar field to integer: “cannot be cast automatically to type integer”

There is no implicit (automatic) cast from text or varchar to integer (i.e. you cannot pass a varchar to a function expecting integer or assign a varchar field to an integer one), so you must specify an explicit cast using ALTER TABLE … ALTER COLUMN … TYPE … USING: ALTER TABLE the_table ALTER COLUMN col_name … Read more