Questions tagged [numeric]

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

It includes questions about algorithms, precision and accuracy of underlying numbers, advantages and disadvantages of several methods, error propagation, problems with the underlying numbers and data structures.

2593 questions
1878
votes
53 answers

How can I check if a string is a valid number?

I'm hoping there's something in the same conceptual space as the old VB6 IsNumeric() function?
Electrons_Ahoy
  • 36,743
  • 36
  • 104
  • 127
1044
votes
41 answers

How to check if a String is numeric in Java

How would you check if a String was a number before parsing it?
Craig Angus
  • 22,784
  • 18
  • 55
  • 63
980
votes
68 answers

How to allow only numeric (0-9) in HTML inputbox using jQuery?

I am creating a web page where I have an input text field in which I want to allow only numeric characters like (0,1,2,3,4,5...9) 0-9. How can I do this using jQuery?
djmzfKnm
  • 26,679
  • 70
  • 166
  • 227
897
votes
10 answers

How can I compare numbers in Bash?

I'm unable to get numeric comparisons working: echo "enter two numbers"; read a b; echo "a=$a"; echo "b=$b"; if [ $a \> $b ]; then echo "a is greater than b"; else echo "b is greater than a"; fi; The problem is that it compares the number…
advert2013
  • 9,734
  • 3
  • 24
  • 35
240
votes
5 answers

Is it possible to set a number to NaN or infinity?

Is it possible to set an element of an array to NaN in Python? Additionally, is it possible to set a variable to +/- infinity? If so, is there any function to check whether a number is infinity or not?
Bob
  • 10,741
  • 27
  • 89
  • 143
156
votes
11 answers

Is there any way to use a numeric type as an object key?

It seems that when I use a numeric type as a key name in an object, it always gets converted to a string. Is there anyway to actually get it to store as a numeric? The normal typecasting does not seem to work. Example: var userId = 1; console.log(…
Spot
  • 7,962
  • 9
  • 46
  • 55
145
votes
5 answers

How to sort numbers correctly with Array.sort()?

In multiple browsers, the following code doesn't sort the numbers correctly: a = new Array(); a.push(10); a.push(60); a.push(20); a.push(30); a.push(100); document.write(a.sort()) It returns 10,100,20,30,60. Anyone know why?
Some Guy
  • 15,854
  • 10
  • 58
  • 67
135
votes
6 answers

How to convert a number to string and vice versa in C++

Since this question gets asked about every week, this FAQ might help a lot of users. How to convert an integer to a string in C++ how to convert a string into an integer in C++ how to convert a floating-point number to a string in C++ how to…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
122
votes
13 answers

Evaluating string "3*(4+2)" yield int 18

Is there a function the .NET framework that can evaluate a numeric expression contained in a string and return the result? F.e.: string mystring = "3*(2+4)"; int result = EvaluateExpression(mystring); Console.Writeln(result); // Outputs 18 Is there…
sindre j
  • 4,404
  • 5
  • 31
  • 32
119
votes
5 answers

What's the difference between integer class and numeric class in R

I want to preface this by saying I'm an absolute programming beginner, so please excuse how basic this question is. I'm trying to get a better understanding of "atomic" classes in R and maybe this goes for classes in programming in general. I…
Keon
  • 1,741
  • 3
  • 17
  • 27
104
votes
9 answers

Converting from an integer to its binary representation

Has anyone got an idea if there is any inbuilt functionality in Go for converting from any one of the numeric types to its binary number form. For example, if 123 was the input, the string "1111011" would be the output.
cobie
  • 7,023
  • 11
  • 38
  • 60
97
votes
6 answers

Generic constraint to match numeric types

I'm trying to write an extension method on numeric types to be used in a fluent testing framework I'm building. Basically, I want to do this: public static ShouldBeGreaterThan(this T actual, T expected, string message) where T : int || T:…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
94
votes
4 answers

How to create a numeric vector of zero length in R

I wonder, how can I create a numeric zero-length vector in R?
Surjya Narayana Padhi
  • 7,741
  • 25
  • 81
  • 130
81
votes
5 answers

Why SQL Server throws Arithmetic overflow error converting int to data type numeric?

I have an error being thrown by SQL Server Management Studio when running this code: declare @percentage numeric(3,2) set @percentage = cast(15 as numeric(3,2)) but when I change numeric declaration to declare @percentage numeric(4,2) set…
Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161
80
votes
6 answers

PHP: Best way to check if input is a valid number?

What is the best way of checking if input is numeric? 1- +111+ 5xf 0xf Those kind of numbers should not be valid. Only numbers like: 123, 012 (12), positive numbers should be valid. This is mye current code: $num = (int) $val; if ( …
medusa1414
  • 1,139
  • 1
  • 9
  • 14
1
2 3
99 100