numbers

How to prevent inserting value that is greater than to max in number field in html

戏子无情 提交于 2019-11-29 12:03:05
I am using number field in html5, here is my code, <input type="number" class="edit-items" /> i set the max of this number field using javascript. element.max = quantity; element.min = 0; element.step = 1; If i am using the arrow-up in the number field. Greater value than the max is not possible. But when I tried to insert in the field, greater value than the max is possible. I would like to prevent it. How? Like you said input of type number will work fine with arrows and not with manual change so try to use oninput event to help you control user inputs : document.getElementsByClassName('edit

Why variable can not start with a Number?

試著忘記壹切 提交于 2019-11-29 11:15:41
I am working in PHP, I have to define variables in sequence to save in Mysql. Both field name and variable name must be same in my case. Can I declare a variable like this $1 OR $2 etc If not why not and if yes why yes? I tried: $id = 0; $6 = $_REQUEST['6']; $7 = $_REQUEST['7']; $8 = $_REQUEST['8']; $xary = array('6','7','8','9') $oAppl->save_record("tablename", $id, "id"); which give me error. Also can I create and use fields in Mysql with the same name? This is how PHP was designed. You can't start a variable name with a number. What you can do is use underscore: $_6 = $_REQUEST['6']; EDIT:

How can I randomize numbers in an array [duplicate]

本小妞迷上赌 提交于 2019-11-29 11:12:09
This question already has an answer here: Most efficient way to randomly “sort” (Shuffle) a list of integers in C# 12 answers I have an array like this one: int[] numbers = new [] { 1, 2, 3, 4 }; I'd like to randomize this (different each time) so that it makes another array with the same size and numbers but in a different order each time. Try something like this: System.Random rnd = new System.Random(); var numbers = Enumerable.Range(1, 4).OrderBy(r => rnd.Next()).ToArray(); Here's a method that will work: public List<int> Randomize(int[] numbers) { List<int> randomized = new List<int>();

How to set locale for numbers in angular 2.0

浪子不回头ぞ 提交于 2019-11-29 11:04:22
The number format in Swiss German is like "100'000.00" (not "100,000.00"). How can I change that? I tried to change the settings in number_pipe.js from en-US to de-CH without success. var defaultLocale: string = 'de-CH'; Is there a workaround or do I have to implement my own pipe? Try using the locale-number .pipe.ts or you could create a simple pipe based on NumeralJs to format numbers https://github.com/adamwdraper/Numeral-js If you only need one locale for your app, you can as of now (@angular ~2.4.0) register the locale provider in @NgModule. @NgModule({ ... providers: [ {provide: LOCALE

How to express numbers in scientific notation in java? [duplicate]

喜夏-厌秋 提交于 2019-11-29 11:00:26
问题 This question already has an answer here: Format double value in scientific notation 4 answers I'm writing a program that deals with planets' mass and diameter; These quantities are expressed in scientific notation. My question is NOT, mind you, NOT how does one print large numbers the right way (That's using printf(), duh), its how I would... "type" these numbers, I guess you could say. For example, the mass of mercury is expressed: 3.30 x 10ˆ23 And in my array of planet masses, an element

How to check if a int var contains a specific number

回眸只為那壹抹淺笑 提交于 2019-11-29 10:57:25
How to check if a int var contains a specific number I cant find a solution for this. For example: i need to check if the int 457 contains the number 5 somewhere. Thanks for your help ;) matt.dolfin 457 % 10 = 7 * 457 / 10 = 45 45 % 10 = 5 * 45 / 10 = 4 4 % 10 = 4 * 4 / 10 = 0 done Get it? Here's a C implementation of the algorithm that my answer implies. It will find any digit in any integer. It is essentially the exact same as Shakti Singh's answer except that it works for negative integers and stops as soon as the digit is found... const int NUMBER = 457; // This can be any integer const

compare two python strings that contain numbers

只愿长相守 提交于 2019-11-29 10:52:16
UPDATE: I should have specified this sooner, but not all of the names are simply floats. For example, some of them are "prefixed" with "YT". So for example" YT1.1. so, you have the same problem YT1.9 < YT1.11 should be true. I'm really surprised that the string comparison fails.... hello, this should be a pretty simple question but I can't seem to find the answer. I'd like to sort a bunch of XL worksheets by name. Each of the names are numbers but in the same way that textbook "sections" are numbered, meaning section 4.11 comes after 4.10 which both come after 4.9 and 4.1. I thought simply

Java - Format number to print decimal portion only

限于喜欢 提交于 2019-11-29 10:24:09
Is there a simple way in Java to format a decimal, float, double, etc to ONLY print the decimal portion of the number? I do not need the integer portion, even/especially if it is zero! I am currently using the String.indexOf(".") method combined with the String.substring() method to pick off the portion of the number on the right side of the decimal. Is there a cleaner way to do this? Couldn't find anything in the DecimalFormat class or the printf method. Both always return a zero before the decimal place. You can remove the integer part of the value by casting the double to a long. You can

java.lang.Number doesn't implement “+” or any other operators?

自闭症网瘾萝莉.ら 提交于 2019-11-29 10:21:01
I'm creating a class which is supposed to be able to be used with an array of any type of number (float, int, etc), so here is one method I have: // T extends Number public synchronized T[] average() { Number[] ret = new Number[queue[0].length]; for (int i = 0; i < ret.length; ++i) { for (int j = 0; j < size; ++j) { ret[i] += queue[j][i]; // WTF ERROR?! } ret[i] /= size; // WTF ERROR?! } return (T[])ret; } Except this won't compile because "Number" doesn't implement the "+=" or "/=" operators. Event worse, java's Number class doesn't implement even the most basic operators like "+" or "-"! How

Javascript: url containing random number

淺唱寂寞╮ 提交于 2019-11-29 10:12:26
A friend is linking my page from his site. As I need users to avoid caching when visiting my page, I want the url to have this form: http://www.mypage.com/index.php?456646556 Where 456646556 is random number. As my friend does not have installed php, how can I build the link with the random number using Javascript? Also my friend asked me to give him just the url, with no further functions as his page is already loaded with them. Can it be done? Thanks a lot I would add a parameter but you can leave it out if needed: var url = "http://www.mypage.com/index.php?rnd="+Math.random() or var url =