Questions tagged [int]

A data type that represents an integer. An integer is a whole number that can be negative, positive, or zero. (i.e. ...-2, -1, 0, 1, 2...) Use this tag for questions about using, storing, or manipulating integers.

int is a data type that represents an integer (a whole number - not a fraction).

int data types may vary based on:

  • the number of bits used to represent them - 16, 32, etc.
  • whether they allow both negative and positive values (signed integers) or only positive (unsigned integers).

In many (but not all) languages, integers are limited to a specific range due to the way they are stored - for instance, an ISO C 32-bit signed integer can store values from −2,147,483,648 to +2,147,483,647 (-2³¹ to 2³¹-1).

This keyword is often used in C-like languages (including C, C++, Golang, etc.)

9824 questions
3463
votes
32 answers

How can I cast int to enum?

How can an int be cast to an enum in C#?
lomaxx
  • 104,787
  • 56
  • 140
  • 177
3213
votes
49 answers

How do I convert a String to an int in Java?

How can I convert a String to an int in Java? My String contains only numbers, and I want to return the number it represents. For example, given the string "1234" the result should be the number 1234.
Unknown user
  • 40,827
  • 16
  • 36
  • 40
2028
votes
29 answers

Get int value from enum in C#

I have a class called Questions (plural). In this class there is an enum called Question (singular) which looks like this. public enum Question { Role = 2, ProjectFunding = 3, TotalEmployee = 4, NumberOfServers = 5, …
jim
  • 23,608
  • 13
  • 48
  • 66
1761
votes
29 answers

Easiest way to convert int to string in C++

What is the easiest way to convert from int to equivalent string in C++. I am aware of two methods. Is there any easier way? (1) int a = 10; char *intStr = itoa(a); string str = string(intStr); (2) int a = 10; stringstream ss; ss << a; string str…
Nemo
  • 20,986
  • 9
  • 41
  • 56
703
votes
32 answers

How can I convert String to Int?

I have a TextBoxD1.Text and I want to convert it to an int to store it in a database. How can I do this?
turki2009
  • 7,099
  • 2
  • 16
  • 7
698
votes
14 answers

What is size_t in C?

I am getting confused with size_t in C. I know that it is returned by the sizeof operator. But what exactly is it? Is it a data type? Let's say I have a for loop: for(i = 0; i < some_size; i++) Should I use int i; or size_t i;?
Vijay
  • 59,537
  • 86
  • 209
  • 308
678
votes
7 answers

Convert all strings in a list to int

In Python, I want to convert all strings in a list to integers. So if I have: results = ['1', '2', '3'] How do I make it: results = [1, 2, 3]
Michael
  • 6,799
  • 3
  • 12
  • 4
592
votes
23 answers

Convert Int to String in Swift

I'm trying to work out how to cast an Int into a String in Swift. I figure out a workaround, using NSNumber but I'd love to figure out how to do it all in Swift. let x : Int = 45 let xNSNumber = x as NSNumber let xString : String =…
Steve Marshall
  • 7,149
  • 4
  • 13
  • 17
584
votes
21 answers

How can I convert a std::string to int?

Just have a quick question. I've looked around the internet quite a bit and I've found a few solutions but none of them have worked yet. Looking at converting a string to an int and I don't mean ASCII codes. For a quick run-down, we are passed in…
Brandon
  • 6,025
  • 5
  • 15
  • 15
557
votes
10 answers

How to convert an int value to string in Go?

i := 123 s := string(i) s is 'E', but what I want is "123" Please tell me how can I get "123". And in Java, I can do in this way: String s = "ab" + "c" // s is "abc" how can I concat two strings in Go?
hardPass
  • 14,241
  • 15
  • 36
  • 41
554
votes
11 answers

"is" operator behaves unexpectedly with integers

Why does the following behave unexpectedly in Python? >>> a = 256 >>> b = 256 >>> a is b True # This is an expected result >>> a = 257 >>> b = 257 >>> a is b False # What happened here? Why is this False? >>> 257 is 257 True …
Greg Hewgill
  • 828,234
  • 170
  • 1,097
  • 1,237
539
votes
11 answers

Convert int to string?

How can I convert an int datatype into a string datatype in C#?
The Worst Shady
  • 5,848
  • 5
  • 17
  • 15
537
votes
11 answers

What is the size of column of int(11) in mysql in bytes?

What is the size of column of int(11) in mysql in bytes? And Maximum value that can be stored in this columns?
Gaurav
  • 26,880
  • 8
  • 47
  • 76
445
votes
7 answers

Java - Convert integer to string

Given a number: int number = 1234; Which would be the "best" way to convert this to a string: String stringNumber = "1234"; I have tried searching (googling) for an answer but no many seemed "trustworthy".
Trufa
  • 35,711
  • 41
  • 118
  • 180
434
votes
11 answers

Java int to String - Integer.toString(i) vs new Integer(i).toString()

Sometimes java puzzles me. I have a huge amount of int initializations to make. What's the real difference? Integer.toString(i) new Integer(i).toString()
marcolopes
  • 8,929
  • 14
  • 46
  • 65
1
2 3
99 100