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
96
votes
3 answers

Does JavaScript support 64-bit integers?

I have the following code: var str = "0x4000000000000000"; //4611686018427387904 decimal var val = parseInt(str); alert(val); I get this value: "4611686018427388000", which is 0x4000000000000060 I was wondering if JavaScript is mishandling 64-bit…
ahmd0
  • 16,633
  • 33
  • 137
  • 233
95
votes
11 answers

in python how do I convert a single digit number into a double digits string?

So say i have a = 5 i want to print it as a string '05'
Joe Schmoe
  • 1,815
  • 3
  • 15
  • 14
94
votes
7 answers

How to check if a number is included in a range (in one statement)?

I am using Ruby on Rails 3.0.9 and I would like to check if a number is included in a range. That is, if I have a variable number = 5 I would like to check 1 <= number <= 10 and retrieve a boolean value if the number value is included in that…
Backo
  • 18,291
  • 27
  • 103
  • 170
92
votes
11 answers

How can I generate a random number in a certain range?

How can I create an app that generates a random number in Android using Eclipse and then show the result in a TextView field? The random number has to be in a range selected by the user. So, the user will input the max and min of the range, and then…
Smaika
  • 1,187
  • 4
  • 12
  • 20
91
votes
10 answers

JavaScript string and number conversion

How can I do the following in JavaScript? Concatenate "1", "2", "3" into "123" Convert "123" into 123 Add 123 + 100 = 223 Covert 223 into "223"
user366312
  • 16,949
  • 65
  • 235
  • 452
91
votes
5 answers

Why does 0.-5 evaluate to -5?

Suppose I write 0.5 as 0.-5 in unexpected way, but it can still run. What does 0. in 0.-5 do so that it can still run and evaluates to -5? I also tried alert(0.-5+1) which prints -4, does JavaScript ignore 0. in 0.-5?
ocomfd
  • 4,010
  • 2
  • 10
  • 19
91
votes
11 answers

iOS: How to get a proper Month name from a number?

I know that the NSDateformatter suite of functionality is a boon for mankind, but at the same time it is very confusing to me. I hope you can help me out. Somewhere in my code, there is an int representing a month. So: 1 would be January, 2…
Sjakelien
  • 2,255
  • 3
  • 25
  • 43
91
votes
6 answers

When I divide numbers in clojure I get a fraction , how do I get the decimal?

When I do (/ 411 125) , I don't get it in terms of decimal. How do I do that?
unj2
  • 52,135
  • 87
  • 247
  • 375
90
votes
10 answers

Checking if string is numeric in dart

I need to find out if a string is numeric in dart. It needs to return true on any valid number type in dart. So far, my solution is bool isNumeric(String str) { try{ var value = double.parse(str); } on FormatException { return false; }…
scrblnrd3
  • 7,228
  • 9
  • 33
  • 64
89
votes
21 answers

php random x digit number

I need to create a random number with x amount of digits. So lets say x is 5, I need a number to be eg. 35562 If x is 3, then it would throw back something like; 463 Could someone show me how this is done?
user1022585
  • 13,061
  • 21
  • 55
  • 75
89
votes
9 answers

Format string to a 3 digit number

Instead of doing this, I want to make use of string.format() to accomplish the same result: if (myString.Length < 3) { myString = "00" + 3; }
Alex
  • 39,265
  • 21
  • 45
  • 42
88
votes
16 answers

Algorithms based on number base systems?

I've noticed recently that there are a great many algorithms out there based in part or in whole on clever uses of numbers in creative bases. For example: Binomial heaps are based on binary numbers, and the more complex skew binomial heaps are…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
88
votes
6 answers

Confusion between isNaN and Number.isNaN in javascript

I have a confusion in how NaN works. I have executed isNaN(undefined) it returned true . But if I will use Number.isNaN(undefined) it is returning false. So which one i should use. Also why there is so discrepancy in the result.
Pranjal Diwedi
  • 1,012
  • 1
  • 7
  • 8
88
votes
3 answers

Simplest way of getting the number of decimals in a number in JavaScript

Is there a better way of figuring out the number of decimals on a number than in my example? var nbr = 37.435.45; var decimals = (nbr!=Math.floor(nbr))?(nbr.toString()).split('.')[1].length:0; By better I mean faster to execute and/or using a…
PhilTrep
  • 1,521
  • 1
  • 10
  • 23
87
votes
7 answers

Why does JavaScript handle the plus and minus operators between strings and numbers differently?

I don't understand why JavaScript works this way. console.log("1" + 1); console.log("1" - 1); The first line prints 11, and the second prints 0. Why does JavaScript handle the first as a String and the second as a number?
Nirgn
  • 1,879
  • 4
  • 23
  • 28