int

Most Efficient Way to Test Object Type

I have values stored as strings in a DataTable where each value could really represent an int, double, or string (they were all converted to strings during an import process from an external data source). I need to test and see what type each value really is. What is more efficient for the application (or is there no practical differenc...

How do you add an int to a string in C++?

int i = 4; string text = "Player "; cout << (text + i); I'd like it to cout "Player 4" ^ The above is obviously wrong but it shows what I'm trying to do here. Is there an easy way to do this or do I have to start adding new includes? ...

Letters within integers. What are they?

This is an excerpt of code from a class I am working with in Java (below). Obviously the code is defining a static variable named EPSILON with the data type double. What I don't understand is the "1E-14" part. What kind of number is that? What does it mean? final double EPSILON = 1E-14; ...

C++ concatenate string and int

I thought this would be really simple but it's presenting some difficulties. If I have string name = "John"; int age = 21; How do I combine them to get a single string "John21"? ...

How to convert in SQL the number of seconds into a human-readable duration?

In a SQL-database I make some selects, that get an duration (as result of a subtraction between two dates) in seconds as an int. But I want to format this result in a human-readable form like 'hh:mm' or 'dd:hh'. Is that possible in SQL and how can I realize this? ...

How do you convert a C++ string to an int?

How do you convert a C++ string to an int? Assume you are expecting the string to have actual numbers in it ("1", "345", "38944", for example). Also, let's assume you don't have boost, and you really want to do it the C++ way, not the crufty old C way. ...

C# char to int

So I have a char in c#: char foo = '2'; Now I want to get the 2 into an int. I find that Convert.ToInt32 returns the actual decimal value of the char and not the number 2. The following will work: int bar = Convert.ToInt32(new string(foo, 1)); int.parse only works on strings as well. Is there no native function in C# to go fro...

Need a simple RegEx to find a number in a single word

Hi Folks, I've got the following url route and i'm wanting to make sure that a segment of the route will only accept numbers. as such, i can provide some regex which checks the word. /page/{currentPage} so.. can someone give me a regex which matches when the word is a number (any int) greater than 0 (ie. 1 <-> int.max). cheers! ...

static_cast confusion caused by inconsistencies

Why whenever I compile and run the following code in Visual Studio 2008: double value1 = 10.5; double value2 = 15.5; int whole_number = value1 + value2; Console::WriteLine(whole_number); I get an incorrect value of 26 while the answer is 25. However when I use static casts on the doubles, I get the right answer which is 25. How can ...

Why is Java able to store 0xff000000 as an int?

An integer's max value in Java is 2147483647, since Java integers are signed, right? 0xff000000 has a numeric value of 4278190080. Yet I see Java code like this: int ALPHA_MASK = 0xff000000; Can anyone enlighten me please? ...

Why do I have to cast enums to int in C#?

This is my code: internal enum WindowsMessagesFlags { WM_EXITSIZEMOVE = 0x00000232, WM_DISPLAYCHANGE = 0x0000007e, WM_MOVING = 0x00000216, } protected override void WndProc(ref Message m) { switch(m.Msg) { case (int)WindowsMessagesFlags.WM_DISPLAYCHANGE: FixWindowSnapping(); break; ...

how do I pass null to int column in linq

Hi experts, How do we assign null value to int column in LINQ. eg. SQLDBDataContext sqlD = new SQLDBDataContext(); var result = from p in sqlD.loadsRadius(Convert.ToInt32(Request["radius"]), ..... here if Request["radius"] is null gives an error. I could pass 0 via this but I need to change in many already existing procedures. Th...

Convert haskell Int with leading zero to String

Suppose I have a variable of type Int = 08, how can I convert this to String keeping the leading zero? For instance: v :: Int v = 08 show v Output: 8 I want the output to be "08". Is this possible? ...

Python - Parse String to Float or Int

This should be simple - In python, how can I parse a numeric string like "545.2222" to its corresponding float value, 542.2222 or "31" to an integer, 31? EDIT: I just wanted to know how to parse a float string to a float, and (separately) an int string to an int. Sorry for the confusing phrasing/original examples on my part. At any r...

Need help-typecasting in Python

Help me people Last week I asked about unicode conversion.I got only one reply.I need more suggestions. I need to convert strings in Python to other types such as unsigned and signed int 8 bits,unsigned and signed int 16 bits,unsigned and signed int 32 bits,unsigned and signed int 64 bits,double,float,string,unsigned and signed 8 bi...

C# - convert string to int and test success

How can you check whether a string is convertible to an int? Lets say we have data like "House", "50", "Dog", "45.99", I want to know whether I should just use the string or use the parsed int value instead. In Javascript we had this parseInt() function, if the string couldn't be parsed, it would get back NaN. ...

C# 3 byte Ints

I am working on a project where I need to deal at the byte level with integers. Since saving space is a primary consideration, I only need very small (and variable length ints). Is there a way that I can turn the int '4096' into 3 bytes? or '1053' into a 2 bytes? Obviously I cna do it manually = (byte[0] * 256) + (byte[1]), but i was...

Parsing Integer to String C

How does one parse an integer to string(char* || char[]) in C? Is there an equivalent String parseInt(int) method from Java in C? ...

Best Way to get Whole Number part of a Decimal Number

What is the best way to return the whole number part of a decimal (in c#)? (This has to work for very large numbers that may not fit into an int). GetIntPart(343564564.4342) >> 343564564 GetIntPart(-323489.32) >> -323489 GetIntPart(324) >> 324 The purpose of this is: I am inserting into a decimal (30,4) field in the db, and want to e...

Javascript: Cast Math.sqrt to int?

I've searched through google (maybe I didn't look hard enough) but I could not find how to turn Math.sqrt into an int. I want to use Math.sqrt for a for loop and I guess I need it as an int but I can't seem to figure out how to cast the result to an int. So how do I do it? I tried something similar to Java: (int) Math.sqrt(num); Bu...