numbers

How to ensure javascript addition instead of string concatenation (Not always adding integers)

可紊 提交于 2019-12-17 20:49:34
问题 Through my javascript library, I end up with a string that represents a number. Now I want to preform an addition on that number without it doing a string concatenation instead. The solution is easy ( How do I add an integer value with javascript (jquery) to a value that's returning a string?, How to make an addition instead of a concatenation) if your number is always in integer. However my string could be a float or an integer, and at the time of the addition, and I don't know which it will

PHP - sorting an array of filenames with numbers?

不打扰是莪最后的温柔 提交于 2019-12-17 20:08:30
问题 Can anyone tell me how to sort an array containing filenames that start with numbers? Because strings that start with 11, 12, 13 etc are considered lower than 2, it's scewing my results like this: [0] "1. File one.pdf" [1] "11. File eleven.pdf" [2] "12. File twelve.pdf" [3] "2. File two.pdf" [4] "3. File three.pdf" Is there anything I can do to sort these properly? 回答1: You can use natsort. or natcasesort, which is case insensitive. If there is more than numbers (ie. diacritics), you should

HTML5 input type number vs tel

江枫思渺然 提交于 2019-12-17 20:03:21
问题 I'm working on updating some form inputs to HTML5. I'm not interested in validating the data so much as having the numeric key pad on mobile devices. Input type 'tel' seems to do what I want, I get the numeric keypad on iPad/mobile. Input type 'number' will also give me the numeric keypad, but it also includes the spinner box which I don't want. What I want to know is if it's safe to use type="tel" on a credit card input? Or should I use type="number" and try to disable the spinner somehow. I

Javascript extracting number from string

戏子无情 提交于 2019-12-17 19:52:09
问题 I have a bunch of strings extracted from html using jQuery. They look like this: var productBeforePrice = "DKK 399,95"; var productCurrentPrice = "DKK 299,95"; I need to extract the number values in order to calculate the price difference. (So I wend up with ≈ var productPriceDiff = DKK 100"; or just: var productPriceDiff = 100"; ) Can anyone help me do this? Thanks, Jakob 回答1: First you need to convert the input prices from strings to numbers. Then subtract. And you'll have to convert the

Opposite of Number.toExponential in JS

扶醉桌前 提交于 2019-12-17 19:49:49
问题 I need to get the value of an extremely large number in JavaScript in non-exponential form. Number.toFixed simply returns it in exponential form as a string, which is worse than what I had. This is what Number.toFixed returns: >>> x = 1e+31 1e+31 >>> x.toFixed() "1e+31" Number.toPrecision also does not work: >>> x = 1e+31 1e+31 >>> x.toPrecision( 21 ) "9.99999999999999963590e+30" What I would like is: >>> x = 1e+31 1e+31 >>> x.toNotExponential() "10000000000000000000000000000000" I could

C# find biggest number

北城余情 提交于 2019-12-17 18:53:27
问题 It's the first time I am using c# so I am not very familiar with it. I would like to create a simple program to find the biggest number if I have the user entering 3 numbers. I just need to know what to put in the code, because I am not very sure. 回答1: Use Math.Max : int x = 3, y = 4, z = 5; Console.WriteLine(Math.Max(Math.Max(x, y), z)); 回答2: There is the Linq Max() extension method. It's available for all common number types(int, double, ...). And since it works on any class that implements

Float to binary in C++

依然范特西╮ 提交于 2019-12-17 18:47:41
问题 I'm wondering if there is a way to represent a float using a char in C++? For example: int main() { float test = 4.7567; char result = charRepresentation(test); return 0; } I read that probably using bitset I can do it but I'm not pretty sure. Let's suppose that my float variable is 01001010 01001010 01001010 01001010 in binary. If I want a char array of 4 elements, the first element will be 01001010, the second: 01001010 and so on. Can I represent the float variable in a char array of 4

Turn a single number into single digits Python [duplicate]

℡╲_俬逩灬. 提交于 2019-12-17 18:36:34
问题 This question already has answers here : Splitting integer in Python? (10 answers) Closed 5 years ago . I want to make a number , for example 43365644 into single numbers [4,3,3....,4,4] and append it on a list 回答1: This can be done quite easily if you: Use str to convert the number into a string so that you can iterate over it. Use a list comprehension to split the string into individual digits. Use int to convert the digits back into integers. Below is a demonstration: >>> n = 43365644 >>>

Limits of Nat type in Shapeless

时间秒杀一切 提交于 2019-12-17 17:52:50
问题 In shapeless, the Nat type represents a way to encode natural numbers at a type level. This is used for example for fixed size lists. You can even do calculations on type level, e.g. append a list of N elements to a list of K elements and get back a list that is known at compile time to have N+K elements. Is this representation capable of representing large numbers, e.g. 1000000 or 2 53 , or will this cause the Scala compiler to give up? 回答1: I will attempt one myself. I will gladly accept a

MySQL UPDATE with random number between 1-3

橙三吉。 提交于 2019-12-17 17:47:18
问题 Got a big table and I want to add a column that has a randomly chosen number for each record. 1, 2, or 3. Having a hard time. Any ideas? 回答1: Try this: UPDATE tableName SET columnName = FLOOR( 1 + RAND( ) *3 ); From the MySQL documentation for RAND : Returns a random floating-point value v in the range 0 <= v < 1.0. So in the above query, the largest value which could be generated by 1 + RAND()*3 would be 3.999999 , which when floored would give 3. The smallest value would occur when RAND()