numbers

React.js controlled text cursor focus issue

做~自己de王妃 提交于 2019-12-06 19:17:54
问题 I have a simple controlled input of type number like below. <input type="number" value={+value} step={1} onChange={this.updateMyChange} /> My value often returns a decimal number like 123.123 . My problem is, when I try edit the value. The cursor loses focus and shifts to the beginning ignoring the whole numbers as soon as the decimal places are cleared. Like below: How do I address this? Immediately after the decimal places are cleared, the cursor jumps to the beginning thereby making it

One or two numeric digits Regex

和自甴很熟 提交于 2019-12-06 18:38:16
问题 I have the below code. It works only when I have 2 digits. If I have 1 digit doesn't work. I want to work in both cases: one or two digit. var numberRegex = /^[1-9][0-9]$/; I've tried something like this but unfortunately doesn't work: var numberRegex = /^[1-9]?[1-9][0-9]$/; Thanks for support. 回答1: Try this one out: /^\d{1,2}$/; Reading what you have it looks like you don't want to accept numbers like 01 . /^\d{1}|[1-9]\d{1}$/; 回答2: Try this. /^[0-9]|[0-9][0-9]$/ This should do the job.

Why is number + string a string in javascript?

雨燕双飞 提交于 2019-12-06 17:36:58
问题 Sort of trying out some quirks in javascript: First I did console.log("5" + 1); This prints 51, this is normal right, both number and string have a + operator, but since string is the first variable it will convert 1 to a string. Now when I did this: console.log(1 + "5") I expected output to be 6, as I thought it would convert string to a number. However, the magic output was 15. Could anyone more experienced in javascript brighten this up for me? 回答1: Quoting ECMAScript spec The Addition

Number.isNaN doesn't exist in IE

♀尐吖头ヾ 提交于 2019-12-06 17:27:11
问题 Why does not IE support the Number.isNaN function? I can't use simple isNan instead of Number.isNaN 'cause these functions are different! For example: Number.isNaN("abacada") != isNaN("abacada") //false != true I need to abstract string and number and check, is some var really contains NaN (I mean NaN constant, but not-a-number value like strings). someobj.someopt = "blah"/0; someobj.someopt2 = "blah"; someobj.someopt3 = 150; for(a in someobj) if(Number.isNaN(someobj[a])) alert('!'); That

Number pipes in Angular2 not working as I would expect

橙三吉。 提交于 2019-12-06 17:11:55
问题 platform-browser.umd.js:962 ORIGINAL EXCEPTION: 2 is not a valid digit info for number pipes Is what I get from writing this in my template: <li>Percentage satisfied: {{selectedCountry.averageSatisfaction | number:2}}</li> My intention is to produce a decimal number with only two decimals. Can someone please point out what I am doing wrong? Here is the documentation: https://docs.angularjs.org/api/ng/filter/number 回答1: You're probably looking for the DecimalPipe. The formatting is passed as a

Sorting numbers for highscores in java

泪湿孤枕 提交于 2019-12-06 16:08:19
Ive got a highscore system for my game. and i want to be able to sort the numbers in acending order,ive got a way to sort the numbers public static int[] sort(int[] a){ Arrays.sort(a); return a; } but how do i make it so the scores stay with the name of the player that set it? for example me:10 you:50 You should be number 1 and me should be nubmer 2. how to i make it so that the string stays with the int when its sorted? thanks Easiest is to create a class to hold the person's name and score. Make it implement the Comparable interface, in the compareTo(...) method compare the score of the

Displaying lines from text file in a batch file

倾然丶 夕夏残阳落幕 提交于 2019-12-06 15:40:19
问题 I'm tryin' to find a script that will let me display "linenumber# and linenumber# as well as lines#-#" from a text file in a batch file? I found this script here on this site.. @echo off setlocal enabledelayedexpansion if [%1] == [] goto usage if [%2] == [] goto usage SET /a counter=0 for /f "usebackq delims=" %%a in (%2) do ( if "!counter!"=="%1" goto exit echo %%a set /a counter+=1 ) goto exit :usage echo Usage: head.bat COUNT FILENAME :exit And it works great :) But it grabs the number of

How to convert a string 3.0103E-7 to 0.00000030103 in Java?

送分小仙女□ 提交于 2019-12-06 15:14:29
How to convert a string 0E-11 to 0.00000000000 in Java? I want to display the number in non scientific notations. I've tried looking at the number formatter in Java, however I need to specific the exact number of decimals I want but I will not always know. I simply want the number of decimal places as specificed by my original number. I would use BigDecimal.Pass your string into it as a parameter and then use String.format to represent your newly created BigDecimal without scientific notation. Float or Double classes can be used too. Apparently the correct answer is to user BigDecimal and

AJAX POST sends numbers as string

放肆的年华 提交于 2019-12-06 15:06:03
I my AJAX POST request is sending my numeric data to my server as string for some reason... Here are my data and the AJAX request: var data = { projectId: $("#projectId").val(), startDate: $("#startDate").val(), endDate: $("#endDate").val(), num_auto_tests: Number($("#num_auto_tests").val()), num_manual_tests: Number($("#num_manual_tests").val()), num_passed_tests: Number($("#num_passed_tests").val()), num_failed_tests: Number($("#num_failed_tests").val()), num_unran_tests: Number($("#num_unran_tests").val()), test: 3 }; AJAX query: $.ajax({ type: "POST", dataType: "json", url: "/addreport/+

SQL UPDATE row Number

假如想象 提交于 2019-12-06 14:24:40
I have a table serviceClusters with a column identity(1590 values). Then I have another table serviceClustersNew with the columns ID, text and comment. In this table, I have some values for text and comment, the ID is always 1. Here an example for the table: [1, dummy1, hello1; 1, dummy2, hello2; 1, dummy3, hello3; etc.] WhaI want now for the values in the column ID is the continuing index of the table serviceClusters plus the current Row number: In our case, this would be 1591, 1592 and 1593. I tried to solve the problem like this: First I updated the column ID with the maximum value, then I