type-conversion

WPF binding with explicit conversion.

Hello everyone, My question may be a repeat of other conversion question but I feel mine is different. Here goes... [simplified example]. public class DataWrapper<T> { public T DataValue{ get; set; } public DataWrapper(T value) { DataValue = value; } public static explicit operator DataWrapper<T> (T value...

How do I convert a c++ string to a .NET String^ ?

I've been trying to figure out how to convert a string to a String in Visual Studio 2005 with no luck. Here is the relevant code: #include <string> using namespace std; #using <System.dll> using namespace System; string test = "a test string"; So I'm trying to convert test into a String^ to use inside other .NET classes, can anyone ...

VB.NET Conversion problem when trying to convert from base class to subclass (BC30311: "Value of type '<type1>' cannot be converted to '<type2>'")

Hello! Please take a look at the following code: Public Sub Method(Of TEntity As EntityObject)(ByVal entity As TEntity) If TypeOf entity Is Contact Then Dim contact As Contact = entity 'Compile error' Dim contact = DirectCast(entity, Contact) 'Compile error' Dim contact = CType(entity, Contact) 'Compile er...

Convert Session Object to IOrderedQueryable<T>

I need to convert a Session object to an IOrderedQueryable and came up blank. I've thought of creating a wrapper, but its not working properly. Basically, I am pulling a Linq query and would like to store it so that I don't have to pull it each time I visit. There are up to 7-10 parameters per user so it's not something that's great for ...

Converting an Integer to Enum in PostgreSQL

I have created a custom data type enum like so: create type "bnfunctionstype" as enum ( 'normal', 'library', 'import', 'thunk', 'adjustor_thunk' ); From an external data source I get integers in the range [0,4]. I'd like to convert these integers to their corresponding enum values. How can I do this? I'm using PostgreSQL 8.4. ...

Java:Convert long to String?

Hello friends, I am absolutely new to Java and Blackberry development. I've started learning Java and Blackberry development. I just created sample BB app, which can allow to choose the date. DateField curDateFld = new DateField("Choose Date: ", System.currentTimeMillis(), DateField.DATE | DateField.FIELD_LEFT); After choosing the ...

strange double to int conversion behavior in c++

The following program shows the weird double to int conversion behavior I'm seeing in c++: #include <stdlib.h> #include <stdio.h> int main() { double d = 33222.221; printf("d = %9.9g\n",d); d *= 1000; int i = (int)d; printf("d = %9.9g | i = %d\n",d,i); return 0; } When I compile and run the program, I see: g++ test.cp...

Why won't Cast<double>() work on IEnumerable<int>?

Possible Duplicates: Enumerable.Cast<T> extension method fails to cast from int to long, why ? Puzzling Enumerable.Cast InvalidCastException Cast/Convert IEnumerable<T> to IEnumerable<U> ? I'm trying to convert an array of integers to an array of doubles (so I can pass it to a function that takes an array of doubles). The...

Forcing a datatype in MS Access make table query

I have a query in MS Access which creates a table from two subqueries. For two of the columns being created, I'm dividing one column from the first subquery into a column from the second subquery. The datatype of the first column is a double; the datatype of the second column is decimal, with scale of 2, but I want the second column t...

Efficiently convert a long string to long in Java

I've really a long sequence of characters such as 123222222222230000000000001. I want to convert this to a long. What is the most efficient way to do it in Java? UPDATE: The max length of sequence is of 31 characters ...

How to convert DateTime to a number in MySQL?

How can I get the total number of seconds since '1970-01-01 00:00:01' from a DateTime instance in MySQL? ...

Convert a stored md5 string to a decimal value in MySQL

I have a very large table in MySQL. I'm using a CHAR(32) field which contains an MD5 as a string of course. I'm running into an issue where I need to convert this to a decimal value using MySQL. A third party tool runs the query so writing code to do this isn't really an option. MySQL does support storing hex values natively and convert...

How can I check if a string can be converted to a float?

First my context is that of a compiler writer who needs to convert floating point literals (strings) into float/double values. I haven't done any floating point programming the last 15 years so i'm pretty sure this is a total stupid newbie question. double res; errno=0; *res = strtod((const char*)literal,NULL); if (errno==ERANGE) thr...

Dozer: JAXBElements to Java Types?

Hi, I'm trying (with Dozer) to convert a JAXB DTO to a POJO (well, actually, to a JPA-annotated Hibernate entity before persisting it). The problem right now is that right now Dozer does not seem to convert elements from the JAXB JAXBElement<> type to the JAXBElement.getValue() type. So, for example, a JAXBElement s is translated to th...

implicit constructor conversion works on explicit vector::vector, only sometimes

I like to initialize 2-dimensional arrays as vector<vector<int> >(x,y). x is passed to vector<vector<int> >'s constructor and y is passed to vector<int>'s constructor, x times. Although this seems to be forbidden by C++03, because the constructor is explicit, it always works, even on Comeau. I can also call vector::assign like this. But,...

Reinterpret float vector as unsigned char array and back.

Hi all, I've searched and searched stackoverflow for the answer, but have not found what I needed. I have a routine that takes an unsigned char array as a parameter in order to encode it as Base64. I would like to encode an STL float vector (vector) in Base64, and therefore would need to reinterpret the bytes in the float vector as an ...

Dynamic typecasting in asp.net mvc Edit action: how can I handle multiple datatypes without throwing an exception?

I'm making a generic MVC viewer/editor for data objects I've designed, modeled after ActiveRecord. The data objects are completely generic, they can have primary keys that are strings, ints, int16s, whatever the database uses (the persistence layer at this organization uses all sorts of datatypes for primary keys and I want this MVC "br...

How to overload some Groovy Type conversion for avoiding try/catch of NumberFormatException ?

I am sick of encapsuling each call of asType with try/catch block like : def b = "" def c try { c = b as Integer } catch (NumberFormatException) { c = null } println c instead I would like to write in my code the following: def b = "" def c = b as Integer and if b is not well-formatted, then I want to have null be assigne...

How can I convert OTF/TTF files to EOT format?

I need to use @font-face feature and my fonts are in OTF/TTF format and Microsoft browsers support only EOT format. I tried to use Microsoft tool WEFT, but it didn't work or I didn't understand how it works. Is there any other way to convert my fonts to EOT format? ...

Unexpected rounding when using ISNULL in sybase sql anywhere

Hi there, I have to work with a legacy system based on SQL Anywhere 5, db access layer is in C++ using embedded SQL. The problem I have is not really a C++ problem, but embedded SQL forces us to SQL statements which cannot be dynamically generated. There are many tables containing a lot of columns having the datatype double. Though the ...