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
115
votes
26 answers

How to convert floats to human-readable fractions?

Let's say we have 0.33, we need to output 1/3. If we have 0.4, we need to output 2/5. The idea is to make it human-readable to make the user understand "x parts out of y" as a better way of understanding data. I know that percentages is a good…
Swaroop C H
  • 16,902
  • 10
  • 43
  • 50
115
votes
7 answers

Java's L number (long) specification

It appears that when you type in a number in Java, the compiler automatically reads it as an integer, which is why when you type in (long) 6000000000 (not in integer's range) it will complain that 6000000000 is not an integer. To correct this, I…
jbu
  • 15,831
  • 29
  • 82
  • 105
113
votes
8 answers

Input type "number" won't resize

Why won't my input resize when I change the type to type="number" but it works with type="text"? EXAMPLE Email:
number:
SaturnsEye
  • 6,297
  • 10
  • 46
  • 62
111
votes
17 answers

Remove/ truncate leading zeros by javascript/jquery

Suggest solution for removing or truncating leading zeros from number(any string) by javascript,jquery.
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
107
votes
16 answers

Number.sign() in javascript

Wonder if there are any nontrivial ways of finding number's sign (signum function)? May be shorter / faster / more elegant solutions than the obvious one var sign = number > 0 ? 1 : number < 0 ? -1 : 0; Short answer! Use this and you'll be safe…
disfated
  • 10,633
  • 12
  • 39
  • 50
106
votes
7 answers

Find the greatest (largest, maximum) number in a list of numbers

How can I easily find the greatest number in a given list of numbers? See also How do I find the maximum (larger, greater) of 2 numbers? - in that special case, the two values can also be compared directly.
Chris Foster
  • 2,639
  • 2
  • 23
  • 30
105
votes
17 answers

Is C# Random Number Generator thread safe?

Is C#'s Random.Next() method thread safe?
noone
  • 1,061
  • 2
  • 7
  • 4
104
votes
6 answers

Large Numbers in Java

How would I go about doing calculations with extremely large numbers in Java? I have tried long but that maxes out at 9223372036854775807, and when using an integer it does not save enough digits and therefore is not accurate enough for what I…
Petey B
  • 11,439
  • 25
  • 81
  • 101
104
votes
25 answers

How to format a number using comma as thousands separator in C?

In C, how can I format a large number from e.g. 1123456789 to 1,123,456,789? I tried using printf("%'10d\n", 1123456789), but that doesn't work. Could you advise anything? The simpler the solution the better.
goe
  • 5,207
  • 14
  • 45
  • 49
103
votes
9 answers

How can I use JavaScript to limit a number between a min/max value?

I want to limit a number between two values, I know that in PHP you can do this: $number = min(max(intval($number), 1), 20); // this will make $number 1 if it's lower than 1, and 20 if it's higher than 20 How can I do this in javascript, without…
Alexandra
  • 1,033
  • 2
  • 7
  • 4
103
votes
17 answers

Is there a way to convert number words to Integers?

I need to convert one into 1, two into 2 and so on. Is there a way to do this with a library or a class or anything?
Llyod
102
votes
7 answers

Does Java have mutable types for Integer, Float, Double, Long?

I am in a situation where I want to use mutable versions of things like Integer. Do I have to use these classes (below) or does Java have something built in? http://www.java2s.com/Code/Java/Data-Type/Amutableintwrapper.htm
smuggledPancakes
  • 9,881
  • 20
  • 74
  • 113
99
votes
4 answers

How do you set, clear and toggle a single bit in JavaScript?

How to set, clear, toggle and check a bit in JavaScript?
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
99
votes
14 answers

How do I tell if a variable has a numeric value in Perl?

Is there a simple way in Perl that will allow me to determine if a given variable is numeric? Something along the lines of: if (is_number($x)) { ... } would be ideal. A technique that won't throw warnings when the -w switch is being used is…
Derek Park
  • 45,824
  • 15
  • 58
  • 76
99
votes
9 answers

How to convert a byte array to its numeric value (Java)?

I have an 8 byte array and I want to convert it to its corresponding numeric value. e.g. byte[] by = new byte[8]; // the byte array is stored in 'by' // CONVERSION OPERATION // return the numeric value I want a method that will perform the above…
pirate
  • 1,583
  • 3
  • 14
  • 12