type-conversion

Haskell numeric type heirarchy in SICP exercises

I've been learning Haskell recently and was talking to a friend who is working through SICP. We were curious to compare Common Lisp and Scheme and so I decided as an exercise to try to translate exercise 1.29 into Haskell. This exercise uses a function sigma which represents the mathematical Summation function Sigma. This function t...

Why does foreach in C# behave this way and is there a way it gets fixed in the future?

long[] b = new long[1]; int i1 = b[0]; // compile error as it should // no warning at all, large values gets converted to negative values silently foreach (int i2 in b) { } class Customer : Person{} Person[]p = new Person[]{mypers}; // no warning at all, throws typecastexception at runtime foreach (Customer c in p) { } I know they...

Convert a string field with pennies into a dollar amount with 2 decimal places in SQL Server.

I have a field in a table as nvarchar(10), which is used to store a value in pennies. For example, $23.50 is stored as "2350". I need to return this value to the program in Money format. How would I do that in the Select statement? ...

MVVM-Pattern for a Diagraming Application with WPF - Convert enum to xxxViewModel

Hi everybody, I'm trying to apply the MVVM design pattern to a diagramming application. In this application there are different items (for example a rectangle, a circle,...). I would like to save the item type as an enum in my model. In my modelview I made a class for every item type (rectangleViewMode, circleViewMode,...). On my view...

Converting all the DateTime Columns to SqlDateTime Columns in a Datatable

Hi, What I want to do is basically take any generic DataTable and then Convert all the DateTime columns into SqlDateTime Columns. (i.e if the datetime column value = datetime.MinValue then Set it to SqlDateTime.Null) Is there anyway I can do this without altering the original datatable (i.e withoutadding computed columns ) or having t...

Storing UISwitch user input in a persistent object

I am a little confused about the typing in my app, let me explain: I have a persistent custom model class containing several boolean attributes. At least it says BOOL in the entity builder, when I model my object there. When I let XCode autocreate the class for me, I can see in the header file that XCode has made NSNumber objects of my ...

Python: convert swig object...

I am using SWIG to create a Python wrapper around a piece of C++ code which returns an object like this: TH1F*GetHist(); (The class TH1F has not been written by me.) Now under Python this results in an <Swig Object of type 'TH1F *' at 0x12da820> My problem is that I would like to use methods of this object which SWIG does not know ...

C# help with Extension Method - Converting collection to another type

I want to convert from public class Party { public string Type { get; set; } public string Name { get; set; } public string Status { get; set;} } and convert to public class Contact { public string Type { get; set; } public string Name { get; set; } public string Status { get; set;...

Why doesn't GLib's GValue system include string to number transformations?

The GValue system in GLib includes standard type transformations using GType descriptors (in fact the GValue reference page includes some sample code that transforms a value from int to string). However, as one can also see from the gvaluetransform source code, transformations from string to numeric values are not included by default. I...

How would I convert this javascript to jquery?

function loaded() { document.addEventListener('touchmove', function(e){ e.preventDefault(); }); myScroll = new iScroll('scroller'); } document.addEventListener('DOMContentLoaded', loaded); If its possible... Thanks :) ...

Polymorphic QSharedPointer

I'm trying to use QSharedPointer in my polymorphic stucture, but I couldn't find right syntax to convert pointer of base class to pointer of derived class. struct Switch : State { int a; }; QSharedPointer <State> myState=QSharedPointer <State>(new Switch); QSharedPointer <Switch> mySwitchTest= ??? myState; What should I put in th...

is there a generic Parse() function that will convert a string to any type using parse?

well i want to convert a string to a generic type like int or date or long based on the generic return type basically a function like Parse(String) that returns an item of type T. for example if a int was passed the function should do int.parse internally thanks ...

Retrieving a max date from DB2 in Java throwing wrong column type conversion exception

I have the following SQL that returns the max BILL_DATE based on some criteria. BILL_DATE is defined in the database as a DATE. SELECT MAX(BILL_DATE) FROM BILLTABLE WHERE col1 = ? and col2 = ? But when I read the value from the resultSet. bill.setBillDate(resultSet.getDate(1)); An exception is thrown: Invalid data conversion...

HTTP Array Parameters with Struts 2 via an Ajax Call

I'm having an issue sending array parameters to a Struts 2 action class. I am using struts 2.1.8.1. Here is some example code: public class MyAction extends ActionSupport { private String[] types; public String execute() { return SUCCESS; } public String[] getTypes() { return types; } public...

How to convert from LPCTSTR to LPSTR?

I have the following line of code: LPSTR address = T2A((LPTSTR)hostAddress); Can I convert LPCTSTR hostAddress to LPSTR without using T2A macros from "afxpriv.h"? ...

make switch use === comparison not == comparison In PHP

Is there anyway to make it so that the following code still uses a switch and returns b not a? Thanks! $var = 0; switch($var) { case NULL : return 'a'; break; default : return 'b'; break; } Using if statements, of course, you'd do it like this: $var = 0; if($var === NULL) return 'a'; else return 'b'; But for more complex ex...

Can I make the ternary operator treat my class like a bool?

I've recently been doing a huge refactoring where I was changing a lot of my code to return booleans instead of an explicit return code. To aid this refactoring I decided to lean on the compiler where possible by getting it to tell me the places where my code needed to be changed. I did this by introducing the following class (see here...

Implicit type conversions - Compiler error.

This question is related to this question. The following code compiles fine VC9 compiler but gives the error when compied with Comeau online. Can anybody tell me which one is correct and what is the meaning of the error? error: ambiguous "?" operation: second operand of type "TypesafeBool" can be converted to third operand type ...

How to print unsigned int value as a time string in C

I need to print this value as a time string to Mon 16-Aug-2010 06:24 format or something similar. unsigned int t = 1281920090; ...

How can i get the numerical value (convert it to int) from a string?

I only see strings with only numbers. this is my string. SMUL 9 A B How can I get the number 9 as int type. Other possible string may be: SMUL 13 A B SMUL 43 100 21 ...