# number « math « Javascript Data Type Q&A

Home
Javascript Data Type Q&A
 1 Array 2 Clojure 3 date 4 decimal 5 function 6 global 7 loop 8 math 9 number 10 object 11 Regular Expression 12 scope 13 String 14 Var 15 variable
 Javascript Data Type Q&A » math » number

### 1. Javascript max() function for 3 numbers    stackoverflow.com

I need to find the highest number from 3 different numbers. The only thing I've found is max() but you can only use 2 numbers. Whats the best way?

### 2. Round Down Number    stackoverflow.com

How can I round down a number in Javascript? math.round() doesn't work because it rounds it to the nearest decimal. I'm not sure if there is a better way of doing it ...

### 3. rounding in base 10    stackoverflow.com

I have a function to round a number given to the function to the nearest whole pence.

``````<script type='text/javascript'>
Math.roundNumber = function(a,b){
if(!isNaN(parseInt(a))){
c = Math.pow(10,b);
...``````

### 4. Dealing with Negative Numbers in Strings    stackoverflow.com

I have a simple, but perplexing problem, with Math. The following code will take a number from a string (usually contained in a span or div) and subtract the value of 1 ...

### 5. Evaluating a string as a mathematical expression in javascript    stackoverflow.com

If I have a string '1+1' is there a way, other than eval(string) to get the numerical value of it i.e. I want to turn '1+1' into 2.

### 6. How to calculate the curve of a linear floating point number in Javascript?    stackoverflow.com

How do I calculate a curve of a linear floating point number (0 to 1) and get another floating point number as a result? What I want is up until the ...

### 7. JavaScript: remove insignificant trailing zeros from a number?    stackoverflow.com

Have I missed a standard API call that removes trailing insignificant zeros from a number? Ex.

``````var x = 1.234000 // to become 1.234;
var y = 1.234001; // stays 1.234001
``````
Number.toFixed() and Number.toPrecision() are ...

### 8. Determine the optimal combination of coins for a dollar amount    stackoverflow.com

I need to find the most optimal combination of coins that makes up a certain dollar amount. So essentially, I want to use the least amount of coins to get ...

### 9. How to convert a number 30.006649999999994 to 30.01 in js?    stackoverflow.com

Anyone knows such a function in javascript?

### 10. javascript: calculate x% of a number    stackoverflow.com

I am wondering how in javascript if i was given a number (say 10000) and then was given a percentage (say 35.8%) how would I work out how much that is (eg ...

### 11. What are the chances that JavaScript Math.Random() will create the same number twice in a row?    stackoverflow.com

Is this correct? using - http://en.wikipedia.org/wiki/Binomial_probability Looks like values are from .0000000000000000 to .9999999999999999 Probability of happening twice = p^2 = (1/9999999999999999)^2 = 1.0 e-32 I think I am missing ...

### 12. JavaScript rounding numbers    stackoverflow.com

I know that I can round a number like this

``````var number = 1.3;
Math.round(number);
``````
and the result I'm given is `1`. But how can I round a number to the next highest whole number? ...

### 13. Determining Cross Over of Numbers    stackoverflow.com

Lets say I have this data set... var a = [5,6,7]; var b = [9,8,6]; Imagine that those values were plotted the y in a (x,y) coordinate pair, and the x was the array ...

### 14. Find the number in an array that is closest to a given number    stackoverflow.com

Good afternoon, I have an Array of integers in javascript, `[5,10,15,20,25,30,35]` when given a number x, how can I find the element in the array that is closest to that number? If the ...

### 15. How do I generate an inverse diamond from one number?    stackoverflow.com

So a friend of mine had an interesting homework assignment. Her task was to create a diamond based on user input. Sample diamond based on input of (5) is:

``````************
***** ...``````

### 16. Making a random number that's a multiple of 10    stackoverflow.com

I'm looking to create a random number between two ranges that is a multiple of 10. For example, if I fed the function the parameters `0, 100` it would return one of ...

### 17. When extending javascript functionality, what is the difference between Number and Math function?    stackoverflow.com

I have extended javascripts core functionality by creating a few functions that were useful to me. When creating test cases for a function today I started wondering which way is the ...

### 18. Formula for reducing higher numbers    stackoverflow.com

I honestly can't think of what to search for, but what I've tried hasn't yielded any results, so I apologize if it's been asked already. This is also more of a math ...

### 19. Finding the number of permutation inversions    stackoverflow.com

I was looking at this because I'm trying to make a fifteen puzzle solver. I don't really understand what it's talking about. How would I go about checking if ...

### 20. js generatring a random number going up in 20s    stackoverflow.com

I understand that you can create a random number via javascript with:

``````Math.floor(Math.random()*100);
``````
the problem is i would like the numbers to go up in twenties, so like if it was a number ...

### 21. Determining the pair of natural numbers that closest approximate a square while maintaining a specific area    stackoverflow.com

So, I'm trying to draw an HTML table as close to being a square as possible from a value passed in. For example, if the number passed in is 16, then ...

### 22. JavaScript: Calculate the nth root of a number    stackoverflow.com

I'm trying to get the nth root of a number using JavaScript, but I don't see a way to do it using the built in `Math` object. Am I overlooking something?
If ...

### 23. Math.ceil to nearest five at position 1    stackoverflow.com

Okay.... I have a lot of uncontrolled numbers i want to round:

``````51255 -> 55000
25 -> 25
9214 -> 9500
13135 -> 15000
25123 -> 30000
``````
I have tried modifying the numbers as string and counting length.... But ...

### 24. Using Math.exp() in Javascript with BigDecimal for large floating point numbers    stackoverflow.com

I'm attempting to perform the following calculation in Javascript:

``````e^x / (1 + e^x)
``````
where `x` is a long floating point number. In this instance, I require accuracy to at least the 10th decimal ...

### 25. javascript make a numbers to be multiples of 150    stackoverflow.com

I'm trying to get numbers to be multiples of 150.

``````(all the num > 0)

if num = 0.333333 => output 150
if num = 149.9 => output 150
if num = 150 => output ...``````

### 26. JavaScript Number Split into indivudal digits    stackoverflow.com

Hi I am trying to solve a math problem where I take a number e.g. 45, or 111 and then split the number into separate digits e.g. 4 5 or 1 ...

### 27. convert number to the nearest multiple of 10    stackoverflow.com

in javascript, lets say I got a random number 136, i'd like it to convert it automatically to 140 or if I got 124 to 120 etc or 24 to 20 ...

### 28. percentage function with positive or negative numbers    stackoverflow.com

I couldn't find this question here although it seems simple. lets say that I want to calculate the percentage of an overall distance when i know the start and end positions ie:

``function ...``

### 29. Compare difference between multiple numbers    stackoverflow.com

The problem is that I have array with 5 numbers: 300 295 250 105 100 95 The result needed: the most numbers that have ...