Questions tagged [numbers]

A number is a mathematical object used to count, measure and label. Questions about using numbers in variables processing, numbers processing, conversion, display, logical numerical changes, data type existence, etc. For questions regarding phone numbers, please use tag [phone-number].

Different types of numbers are used in many cases. Numbers can be classified into sets, called number systems.

Natural numbers

The most familiar numbers are the natural numbers or counting numbers (1, 2, 3, ...). Zero is usually not considered a natural number, although definitions vary.

Integers

The integers are formed by the natural numbers (including 0) (0, 1, 2, 3, ...) together with the negatives of the non-zero natural numbers (−1, −2, −3, ...). Viewed as a subset of the real numbers, they are numbers that can be written without a fractional or decimal component, and fall within the set {..., −2, −1, 0, 1, 2, ...}.

Rational numbers

A rational number is a number that can be expressed as a fraction with an integer numerator and a non-zero natural number denominator. Fractions are written as two numbers, the numerator and the denominator, with a dividing bar between them.

A number is rational if (and only if) it can be written as a terminating and/or repeating decimal.

Real numbers

The real numbers include all of the measuring numbers. Real numbers are usually written using decimal numerals, in which a decimal point is placed to the right of the digit with place value one. Each digit to the right of the decimal point has a place value one-tenth of the place value of the digit to its left.

Complex numbers

The complex numbers consist of all numbers of the form

a + b*i

where a and b are real numbers and i is the square root of negative one (the imaginary unit).

More information on Wikipedia

12117 questions
253
votes
3 answers

PHP prepend leading zero before single digit number, on-the-fly

PHP - Is there a quick, on-the-fly method to test for a single character string, then prepend a leading zero? Example: $year = 11; $month = 4; $stamp = $year.add_single_zero_if_needed($month); // Imaginary function echo $stamp; // 1104
Ben
  • 54,723
  • 49
  • 178
  • 224
250
votes
8 answers

How to empty input field with jQuery

I am in a mobile app and I use an input field in order user submit a number. When I go back and return to the page that input field present the latest number input displayed at the input field. Is there any way to clear the field every time the page…
kosbou
  • 3,919
  • 8
  • 31
  • 36
249
votes
16 answers

Phone: numeric keyboard for text input

Is there a way to force the number keyboard to come up on the phone for an ? I just realized that in HTML5 is for “floating-point numbers”, so it isn’t suitable for credit card numbers, ZIP codes, etc. I want…
Tami
  • 3,221
  • 2
  • 18
  • 15
243
votes
20 answers

Get a random number focused on center

Is it possible to get a random number between 1-100 and keep the results mainly within the 40-60 range? I mean, it will go out of that range rarely, but I want it to be mainly within that range... Is it possible with JavaScript/jQuery? Right now I'm…
Darryl Huffman
  • 2,499
  • 3
  • 18
  • 40
236
votes
22 answers

How can I compare two floating point numbers in Bash?

I am trying hard to compare two floating point numbers within a Bash script. I have two variables, e.g. let num1=3.17648e-22 let num2=1.5 Now, I just want do a simple comparison of these two numbers: st=`echo "$num1 < $num2" | bc` if [ $st -eq 1];…
Jonas
  • 2,974
  • 4
  • 24
  • 23
236
votes
23 answers

Testing whether a value is odd or even

I decided to create simple isEven and isOdd function with a very simple algorithm: function isEven(n) { n = Number(n); return n === 0 || !!(n && !(n%2)); } function isOdd(n) { return isEven(Number(n) + 1); } That is OK if n is with certain…
RobG
  • 142,382
  • 31
  • 172
  • 209
236
votes
11 answers

Format Float to n decimal places

I need to format a float to "n"decimal places. was trying to BigDecimal, but the return value is not correct... public static float Redondear(float pNumero, int pCantidadDecimales) { // the function is call with the values Redondear(625.3f, 2) …
seba123neo
  • 4,688
  • 10
  • 35
  • 53
234
votes
9 answers

Removing all non-numeric characters from string in Python

How do we remove all non-numeric characters from a string in Python?
grizzley
  • 2,399
  • 2
  • 14
  • 7
231
votes
13 answers

The maximum value for an int type in Go

How does one specify the maximum value representable for an unsigned integer type? I would like to know how to initialize min in the loop below that iteratively computes min and max lengths from some structs. var minLen uint = ??? var maxLen uint =…
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
222
votes
7 answers

Java Generate Random Number Between Two Given Values

I would like to know how to generate a random number between two given values. I am able to generate a random number with the following: Random r = new Random(); for(int i = 0; i < a.length; i++){ for(int j = 0; j < a[i].length; j++){ …
Mus
  • 7,290
  • 24
  • 86
  • 130
201
votes
6 answers

What is the difference between Int and Integer?

In Haskell, what is the difference between an Int and an Integer? Where is the answer documented?
0xAX
  • 20,957
  • 26
  • 117
  • 206
198
votes
6 answers

Why is Double.MIN_VALUE in not negative

Can anyone shed some light on why Double.MIN_VALUE is not actually the minimum value that Doubles can take? It is a positive value, and a Double can of course be negative. I understand why it's a useful number, but it seems a very unintuitive name,…
mo-seph
  • 6,073
  • 9
  • 34
  • 35
197
votes
34 answers

How to make HTML input tag only accept numerical values?

I need to make sure that a certain field only takes numbers as value. The input is not part of a form. Hence it doesn't get submitted, so validating during submission is not an option. I want the user to be unable to type in any characters…
chtenb
  • 14,924
  • 14
  • 78
  • 116
196
votes
9 answers

What is the best way to tell if a character is a letter or number in Java without using regexes?

What is the best and/or easiest way to recognize if a string.charAt(index) is an A-z letter or a number in Java without using regular expressions? Thanks.
Daniel Sopel
  • 3,535
  • 4
  • 24
  • 17
194
votes
3 answers

Why is it that parseInt(8,3) == NaN and parseInt(16,3) == 1?

I'm reading this but I'm confused by what is written in the parseInt with a radix argument chapter Why is it that parseInt(8, 3) → NaN and parseInt(16, 3) → 1? AFAIK 8 and 16 are not base-3 numbers, so parseInt(16, 3) should return NaN too
Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73