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.)

9665 questions
2314
votes
31 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
  • 26,598
  • 13
  • 51
  • 66
807
votes
31 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
  • 8,139
  • 2
  • 19
  • 7
802
votes
15 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
  • 65,327
  • 90
  • 227
  • 319
753
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
  • 19,033
  • 19
  • 40
  • 42
661
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,919
  • 4
  • 16
  • 17
630
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
  • 28,447
  • 8
  • 50
  • 80
616
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
  • 951,095
  • 183
  • 1,149
  • 1,285
598
votes
12 answers

Convert int to string?

How can I convert an int datatype into a string datatype in C#?
The Worst Shady
  • 6,438
  • 5
  • 19
  • 15
531
votes
6 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
  • 39,971
  • 43
  • 126
  • 190
442
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
  • 9,232
  • 14
  • 54
  • 65
425
votes
9 answers

How to convert float to int with Java

I used the following line to convert float to int, but it's not as accurate as I'd like: float a=8.61f; int b; b=(int)a; The result is : 8 (It should be 9) When a = -7.65f, the result is : -7 (It should be -8) What's the best way to do it ?
Frank
  • 30,590
  • 58
  • 161
  • 244
417
votes
12 answers

Convert boolean to int in Java

What is the most accepted way to convert a boolean to an int in Java?
hpique
  • 119,096
  • 131
  • 338
  • 476
397
votes
12 answers

Leading zeros for Int in Swift

I'd like to convert an Int in Swift to a String with leading zeros. For example consider this code: for myInt in 1 ... 3 { print("\(myInt)") } Currently the result of it is: 1 2 3 But I want it to be: 01 02 03 Is there a clean way of doing…
Jeehut
  • 20,202
  • 8
  • 59
  • 80
369
votes
9 answers

How can I divide two integers to get a double?

How do I divide two integers to get a double?
leora
  • 188,729
  • 360
  • 878
  • 1,366
359
votes
29 answers

Java Array Sort descending?

Is there any EASY way to sort an array in descending order like how they have a sort in ascending order in the Arrays class? Or do I have to stop being lazy and do this myself :[
AFK
  • 4,333
  • 4
  • 23
  • 22
1
2 3
99 100