Test if number is odd or even
What is the simplest most basic way to find out if a number/variable is odd or even in PHP? Is it something to do with mod? I’ve tried a few scripts but.. google isn’t delivering at the moment. 19 Answers 19
What is the simplest most basic way to find out if a number/variable is odd or even in PHP? Is it something to do with mod? I’ve tried a few scripts but.. google isn’t delivering at the moment. 19 Answers 19
I have float numbers like 3.2 and 1.6. I need to separate the number into the integer and decimal part. For example, a value of 3.2 would be split into two numbers, i.e. 3 and 0.2 Getting the integer portion is easy: n = Math.floor(n); But I am having trouble getting the decimal portion. I … Read more
I have a <input type=”number”> and I want to restrict the input of the users to purely numbers or numbers with decimals up to 2 decimal places. Basically, I am asking for a price input. I wanted to avoid doing regex. Is there a way to do it? <input type=”number” required name=”price” min=”0″ value=”0″ step=”any”> … Read more
I have a variable that stores false or true, but I need 0 or 1 instead, respectively. How can I do this? 18 Answers 18
I want to get only positive values, is there any way to prevent it using only html Please don’t suggest validation method 18 Answers 18
I am looking for an easy way in JavaScript to check if a number has a decimal place in it (in order to determine if it is an integer). For instance, 23 -> OK 5 -> OK 3.5 -> not OK 34.345 -> not OK if(number is integer) {…} 22 Answers 22
For <input type=”number”> element, maxlength is not working. How can I restrict the maxlength for that number element? 30 Answers 30
I’d like to see integers, positive or negative, in binary. Rather like this question, but for JavaScript. 15 Answers 15
How do I format a floating number to a fixed width with the following requirements: Leading zero if n < 1 Add trailing decimal zero(s) to fill up fixed width Truncate decimal digits past fixed width Align all decimal points For example: % formatter something like ‘{:06}’ numbers = [23.23, 0.123334987, 1, 4.223, 9887.2] for … Read more
I want to check if a string contains only digits. I used this: var isANumber = isNaN(theValue) === false; if (isANumber){ .. } But realized that it also allows + and -. Basically, I want to make sure an input contains ONLY digits and no other characters. Since +100 and -5 are both numbers, isNaN() … Read more