numbers

How to restrict input number to non-decimal

独自空忆成欢 提交于 2019-12-24 12:57:19
问题 I have a number input on a page, and I want it restricted to whole number values, no decimals. I am using forms and angularjs for validation. What do I have to do to make decimals not allowed? I tried setting step to 1, but this changed nothing. Many other issues discuss getting browsers to support decimals - I seem to be having the opposite problem. 回答1: You can make a custom directive for that, incorporating the ngModelController. Like this: Proof of Concept module.directive("noDecimalInput

Recover the original number from a float

冷暖自知 提交于 2019-12-24 12:43:24
问题 Numbers are being stored in a database (out of my control) as floats/doubles etc. When I pull them out they are damaged - for example 0.1 will come out (when formatted) as 0.100000001490116119384765625 . Is there a reliable way to recover these numbers? I have tried new BigDecimal(((Number) o).doubleValue()) and BigDecimal.valueOf(((Number) o).doubleValue()) but these do not work. I still get the damaged result. I am aware that I could make assumptions on the number of decimal places and

Excel: Sequential numbers + specified start and end values + shift column data down

房东的猫 提交于 2019-12-24 12:35:06
问题 I have a start value in column "A" (02) And an end value in column "B" (06) In column "C" I'd like to list the range of number sequentially using the start and end values in columns "A" and "B". However I'd also like to shift the cell data down to stop any data overlapping. To go one step further, I don't know if this is possible, but it would help if the data from the original row could be duplicated in each of the new rows that have been created with the sequential values. Edit: This code

C# - Need help creating program that simulates Prime Number behavior by drawing lines

六月ゝ 毕业季﹏ 提交于 2019-12-24 12:17:24
问题 I challenged myself to create a program to experiment with Prime Numbers, I already have an idea how to do it, but not the coding skills.. My plan is this: First ill create a program in C# that makes straight lines that follow some rules: rule 1: all lines have the same length. rule 2: all lines are either horizontal or vertical (no diagonals). rule 3: Every new line begins where the previous line has ended (that way all the lines are joined). Now for the tricky part: I would like to make a

What is the minimal step in double data type? (.NET)

谁说胖子不能爱 提交于 2019-12-24 12:15:47
问题 My question is a bit theoretical but actually I need it in practice. Let's assume that we have two double variables X and Y . Y is certain next double number of X (as you already know we can't keep any real number in double because real number are infinite even in 0 to 1 interval). Does (Y - X) is constant? And if yes what is it's value? P.S. My question is related to Microsoft.NET Framework. 回答1: The minimum difference between two double values in .NET is Double.Epsilon. As for comparing

how to convert char to number in matlab?

一笑奈何 提交于 2019-12-24 11:27:09
问题 Please help me with the following problem: In matlab, I have an Nx3 char variable, where N can vary depending on the input. Let's say N = 5 and I have the following variable A (5x3 char): A = [' 1Y'; ' 5Y'; '10Y'; '15Y'; '20Y'] Is there a way to define a new variable B having as values the numbers in variable A, i.e. B=[1; 5; 10; 15; 20] ? Thank you for your help! 回答1: Since your input is a character array, first convert each row into a cell to allow use with the string functions in MATLAB:

Efficient way to create and fill an array with consecutive numbers in range

徘徊边缘 提交于 2019-12-24 11:15:56
问题 for the moment i use this JavaScript to create an array with n numbers from 0 to n // javascript populate array var n=1000; var arr=[n]; for (i=n;i>=0;i--) { arr[i]=i; console.log(arr[i]); } is it the fast/right way to do the task? 回答1: You can do declarative approach while using Array.from like this: arr = Array.from({length: 20}, (e, i)=> i) console.log(arr) 回答2: An ES6 way of doing it using Array.keys(): let n = 10; let arr = Array.from(Array(n).keys()); console.log(arr); Made a quick

define sum function in Ruby

本秂侑毒 提交于 2019-12-24 10:57:00
问题 Please help, I am a Ruby student, I know how to do the .sum method but not this: how do you define a sum function for an array so that providing any elements will result in the sum of them. The format should be sum([array inputs]) return sum of array elements. For ex: sum([ ]) should return 0, sum([1,2,3]) returns 6 (#again, not [1,2,3].sum). I am so stuck in the box, thank you very much for any help. 回答1: Solution with usage of Enumerable#inject: def sum(array) array.inject(0){|sum, el| sum

how to get numbers separated by comma entered in a line into an array in Java

岁酱吖の 提交于 2019-12-24 10:47:11
问题 how could I get values entered in a single line by the user eq: 1, 3, 400, 444, etc.. into an array. I know I must declare a separator in this case the comma ",". Could someone help Thanks 回答1: String input = "1, 3, 400, 444"; String[] numbers = input.split("\\s*,\\s*"); You can use much simpler separator in String.split() like "," but the more complex "\\s*,\\s*" additionally strips whitespaces around comma. 回答2: Try this: String line = "1, 3, 400, 444"; String[] numbers = line.split(",\\s+"

Initial number part or integer portion of a string in xsl

痴心易碎 提交于 2019-12-24 10:39:44
问题 By using xsl template, can any one tell me the way to get first number portion of a string field For example: '12' -> should result in -> 12 '5 ASDF' -> should result in -> 5 '34SDF56' -> should result in -> 34 回答1: Here is a one-liner XPath solution : :) <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="text()"> <xsl:variable name="vS" select="concat(.,'Z')"/> <xsl:value-of select= "substring-before(translate($vS