numbers

Comma-formated numbers in jQuery

烂漫一生 提交于 2019-12-24 22:24:08
问题 I have following function in jQuery to format the number into comma-formatted: function CommaFormattedN(amount) { var delimiter = ","; var i = parseInt(amount); if(isNaN(i)) { return ''; } i = Math.abs(i); var minus = ''; if (i < 0) { minus = '-'; } var n = new String(i); var a = []; while(n.length > 3) { var nn = n.substr(n.length-3); a.unshift(nn); n = n.substr(0,n.length-3); } if (n.length > 0) { a.unshift(n); } n = a.join(delimiter); amount = minus + n; return amount; } I am calling this

Code to generate Permutations for a given set of numbers efficiently C#

╄→гoц情女王★ 提交于 2019-12-24 21:42:15
问题 Can anyone please write or give me a link where I can find the C# code to list all the permutations for a give set of numbers in the most efficient manner? 回答1: Not sure how efficient these are, but here are some options: http://www.codeproject.com/KB/recipes/Combinatorics.aspx http://www.codeproject.com/KB/recipes/premutations.aspx A C# implementation of Knuth's solution 回答2: A little bit too late... Just as reference... According to my tests, my implementation of Heap's algorithm seems to

What's a good way to store extremely large numbers? (Eg. 572e6561) in C#

房东的猫 提交于 2019-12-24 21:39:41
问题 My first thought was to implement a class which stores the coefficient as a double, and the 10^X as an int/short. I want to use engineering notation over scientific notation because it's simpler for end-users. If there are projects for doing this, I can't seem to find them. I know System.Numerics.BigInteger exists, but it's pretty slow. I really want high speed for performing many calculations on mobile devices. I just want to store numbers as engineering notation. Any ideas? 回答1: If you don

how to generate a list of 3-digit numbers?

蹲街弑〆低调 提交于 2019-12-24 20:16:06
问题 How can I generate a list of 3-digit numbers for which the sum of their digits equal 17? For example assuming number XYZ , we would have X+Y+Z=17 This is how far I got: numbers = list(range(1, 1000)) 回答1: It appears that you want the sum of the digits to be 17 and not the sum of the numbers as the "but I want the first number + the second number + the third number = 17 ?" implies. So, take a look at this: result = [x for x in range(100, 1000) if sum(int(y) for y in str(x))==17] print(result)

Find nth occurence of groups of thousands which sum to a given number in lexical order

流过昼夜 提交于 2019-12-24 19:49:19
问题 A previous question asked for the solutions in lexical order (lowest to highest) to a+b+c+d… = x where a,b,c,d… is an arbitrary number of integers between 0-999 and x is a fixed integer An answer was given which fully computes this efficiently using python. However, for very large numbers, the loop could take years to complete. For example, the huge number: 304,153,525,784,175,759 is a solution for x=2700 since the groups of threes add up to 2700 304+153+525+784+175+759 = 2700 However, to

Java - rounding by quarter intervals

有些话、适合烂在心里 提交于 2019-12-24 17:43:32
问题 I'm running into following issue... Does an already 'built-in' function exists in java to round given random numbers to the closest lower quarter value. These are the given random numbers: 2.00 -> 2.00 2.24 -> 2.00 2.25 -> 2.25 2.49 -> 2.25 2.50 -> 2.50 2.74 -> 2.50 2.75 -> 2.75 2.99 -> 2.75 3.00 -> 3.00 回答1: You can multiply the value by 4 then floor it then divide by 4. public static double quarterRound(double v){ return Math.floor(v*4)/4; } 回答2: You need to round to quarters so: Multiply

Java - rounding by quarter intervals

对着背影说爱祢 提交于 2019-12-24 17:43:25
问题 I'm running into following issue... Does an already 'built-in' function exists in java to round given random numbers to the closest lower quarter value. These are the given random numbers: 2.00 -> 2.00 2.24 -> 2.00 2.25 -> 2.25 2.49 -> 2.25 2.50 -> 2.50 2.74 -> 2.50 2.75 -> 2.75 2.99 -> 2.75 3.00 -> 3.00 回答1: You can multiply the value by 4 then floor it then divide by 4. public static double quarterRound(double v){ return Math.floor(v*4)/4; } 回答2: You need to round to quarters so: Multiply

Java - rounding by quarter intervals

喜夏-厌秋 提交于 2019-12-24 17:43:06
问题 I'm running into following issue... Does an already 'built-in' function exists in java to round given random numbers to the closest lower quarter value. These are the given random numbers: 2.00 -> 2.00 2.24 -> 2.00 2.25 -> 2.25 2.49 -> 2.25 2.50 -> 2.50 2.74 -> 2.50 2.75 -> 2.75 2.99 -> 2.75 3.00 -> 3.00 回答1: You can multiply the value by 4 then floor it then divide by 4. public static double quarterRound(double v){ return Math.floor(v*4)/4; } 回答2: You need to round to quarters so: Multiply

Sign magnitude, One's complement, Two's Complement

你离开我真会死。 提交于 2019-12-24 16:24:42
问题 So my professor has a question to make a list of all positive and negative numbers that can be represented in One's, two's complements, and sign magnitude: Using 4 bit numbers, for example (5)10 = ( 0101)2 Write all positive numbers and all negative numbers that can be represented with four bits in sign-magnitude, one’s complement, and two’s complement. Now, I am not looking for the answer just clarification. for sign magnitude, the first bit represents the sign of the number. so in the

How did I beat the Javascript calculator?

百般思念 提交于 2019-12-24 12:59:10
问题 I created the following code to calculate numbers multiplied by eleven using the method I learnt in elementary school: function multiplyby11(number) { var num = number + ""; var integers = num.split(''); var numbers = []; integers.forEach(function (val) { numbers.push(parseInt(val)); }); var multiply = []; multiply.push(numbers[0]); var number_length = numbers.length; for (var i = 1; i < number_length; ++i) { multiply.push(numbers[i] + numbers[i - 1]) } multiply.push(numbers[number_length - 1