numbers
How to generate random positive and negative numbers in Java [duplicate]
You random on (0, 32767+32768) then subtract by 32768
Rounding off decimals in Django
If you don’t care about the commas, then floatformat will do the job: {{ value|floatformat:”0″ }} If you do care about commas, you want: {{ value|floatformat:”0″|intcomma }} (Hat tip to Stephen for pointing me at intcomma!)
Using AWK to filter out column with numerical ranges
awk ‘{ if ($4 >= 1 && $4 <= 10) print $1 }’ sample.txt
sql like operator to get the numbers only
You can use the following to only include valid characters: SQL SELECT * FROM @Table WHERE Col NOT LIKE ‘%[^0-9.]%’ Results Col ——— 234.62 6435.23 2
An improved isNumeric() function?
In my opinion, if it’s an array then its not numeric. To alleviate this problem, I added a check to discount arrays from the logic You can have that problem with any other object as well, for example {toString:function(){return “1.2”;}}. Which objects would you think were numeric? Number objects? None? Instead of trying to blacklist … Read more
Generating the partitions of a number
It’s called Partitions. [Also see Wikipedia: Partition (number theory).] The number of partitions p(n) grows exponentially, so anything you do to generate all partitions will necessarily have to take exponential time. That said, you can do better than what your code does. See this, or its updated version in Python Algorithms and Data Structures by … Read more
Generating non-repeating random numbers in Python
This is a neat problem, and I’ve been thinking about it for a while (with solutions similar to Sjoerd’s), but in the end, here’s what I think: Use your point 1) and stop worrying. Assuming real randomness, the probability that a random number has already been chosen before is the count of previously chosen numbers … Read more
Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array
but as for this method, I don’t understand the purpose of Integer.MAX_VALUE and Integer.MIN_VALUE. By starting out with smallest set to Integer.MAX_VALUE and largest set to Integer.MIN_VALUE, they don’t have to worry later about the special case where smallest and largest don’t have a value yet. If the data I’m looking through has a 10 … Read more
Format Number like Stack Overflow (rounded to thousands with K suffix)
Like this: (EDIT: Tested) static string FormatNumber(int num) { if (num >= 100000) return FormatNumber(num / 1000) + “K”; if (num >= 10000) return (num / 1000D).ToString(“0.#”) + “K”; return num.ToString(“#,0”); } Examples: 1 => 1 23 => 23 136 => 136 6968 => 6,968 23067 => 23.1K 133031 => 133K Note that this will … Read more