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
86
votes
11 answers

add commas to a number in jQuery

I have these numbers 10999 and 8094 and 456 And all i want to do is add a comma in the right place if it needs it so it looks like this 10,999 and 8,094 and 456 These are all within a p tag like this

10999

etc. Can it be…
Jamie Taylor
  • 3,500
  • 21
  • 65
  • 99
86
votes
4 answers

JavaScript adding decimal numbers issue

So I am making a script that adds two numbers (decimal numbers) together, which I have encountered a problem. http://jsfiddle.net/DerekL/esqnC/ I made the script, it turns out pretty good: 0.1 + 0.5 //0.6 0.2 + 0.3 //0.5 But soon I see: 0.1 + 0.2…
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
83
votes
6 answers

Difference between 2 numbers

I need the perfect algorithm or C# function to calculate the difference (distance) between 2 decimal numbers. For example the difference between: 100 and 25 is 75 100 and -25 is 125 -100 and -115 is 15 -500 and 100 is 600 Is there a C# function or a…
Germstorm
  • 9,709
  • 14
  • 67
  • 83
81
votes
3 answers

Adding space between numbers

I'm trying to make a number input. I've made so my textbox only accepts numbers via this code: function isNumber(evt) { evt = (evt) ? evt : window.event; var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode > 31 &&…
user1768788
  • 1,265
  • 1
  • 10
  • 29
81
votes
9 answers

Making all numbers negative

I have a few floats: -4.50 +6.25 -8.00 -1.75 How can I change all these to negative floats so they become: -4.50 -6.25 -8.00 -1.75 Also I need a way to do the reverse If the float is a negative, make it a positive.
dotty
  • 40,405
  • 66
  • 150
  • 195
80
votes
2 answers

Show a leading zero if a number is less than 10

Possible Duplicate: JavaScript equivalent to printf/string.format How can I create a Zerofilled value using JavaScript? I have a number in a variable: var number = 5; I need that number to be output as 05: alert(number); // I want the alert to…
Nicekiwi
  • 4,567
  • 11
  • 49
  • 88
79
votes
6 answers

Print leading zeros with C++ output operator?

How can I format my output in C++? In other words, what is the C++ equivalent to the use of printf like this: printf("%05d", zipCode); I know I could just use printf in C++, but I would prefer the output operator <<. Would you just use the…
Frank
  • 64,140
  • 93
  • 237
  • 324
79
votes
4 answers

How to convert Int to Hex string in Kotlin?

I'm looking for a similar function to Java's Integer.toHexString() in Kotlin. Is there something built-in, or we have to manually write a function to convert Int to String?
milosmns
  • 3,595
  • 4
  • 36
  • 48
77
votes
4 answers

JavaScript Number.toLocaleString() with 4 digits after separator

Is there a way to get number.toLocaleString() with 4 digits after the comma? Example: var number = 49.9712; document.getElementById('id').innerText = number.toLocaleString(); Result: 49,9712 But now it always returns number with 2 digits after…
Artem
  • 1,937
  • 1
  • 14
  • 19
77
votes
17 answers

Format numbers in JavaScript similar to C#

Is there a simple way to format numbers in JavaScript, similar to the formatting methods available in C# (or VB.NET) via ToString("format_provider") or String.Format()?
xiemails
  • 843
  • 3
  • 8
  • 10
75
votes
8 answers

PHP remove commas from numeric strings

In PHP, I have an array of variables that are ALL strings. Some of the values stored are numeric strings with commas. What I need: A way to trim the commas from strings, and ONLY do this for numeric strings. This isn't as straightforward as it…
user1082428
  • 1,081
  • 3
  • 12
  • 14
75
votes
4 answers

Formatting money in twig templates

Are there any filters or something like that in twig template engine to format money or numbers?
umpirsky
  • 9,902
  • 13
  • 71
  • 96
74
votes
10 answers

How do I find the difference between two values without knowing which is larger?

I was wondering if there was a function built into Python that can determine the distance between two rational numbers but without me telling it which number is larger. e.g. >>>distance(6,3) 3 >>>distance(3,6) 3 Obviously I could write a simple…
Rapid
  • 1,442
  • 1
  • 13
  • 25
74
votes
8 answers

Generics - where T is a number?

I'm trying to figure a way to create a generic class for number types only, for doing some calculations. Is there a common interface for all number types (int, double, float...) that I'm missing??? If not, what will be the best way to create such a…
CD..
  • 72,281
  • 25
  • 154
  • 163
73
votes
11 answers

How to write fraction value using html?

I want to write fraction value such as the picture below: How do I write fraction value using html without using image? NOTE: I don't want this 1 1/2 pattern but strictly just as the pic above
user774411
  • 1,749
  • 6
  • 28
  • 47