How do you order by number if your number can fall below and be bigger than 0?
Example Mysql table:
|Name|Karma|
__________
|Me | -8 |
|Bill| 5 |
|Tom | 2 |
|Saly| 0 |
|San.| -3 |
Example select query
$sql="SELECT karma FROM table ORDER BY karma DESC";
The result I get is this (separated by comma): 5,2,0,-8,-3.
Shouldn't...
I need to generate a random number.
But the twist is that the % of lower numbers should be greater than the higher.
For example.
rand > 1 to 100
13,
15,
12,
16,
87,
15,
27,
12,
1,
12,
98,
12,
53,
12,
14....
The bold integers will be the ones return from the 1-100 range.
The math should be like so rand = a number lower than max/2
...
I read that the random number generator dev/random on Mac and Solaris includes 160 bits of entropy. What can I do, if I need more entropy, for example, 200 bits? Thanks in advance
...
Hello,
is there a simple way to round the result of a division to upper integer ?
I would like to have this :
18/20 -> 1
19/20 -> 1
20/20 -> 1
21/20 -> 2
22/20 -> 2
23/20 -> 2
... and so on ...
38/20 -> 2
39/20 -> 2
40/20 -> 2
41/20 -> 3
42/20 -> 3
43/20 -> 3
Must I manager with NSNumberFormatter stuff ?
I didn't success to get ...
How can I do this elegantly with C# and .Net 3.5/4?
For example a number can be between 1 and 100.
Edit: I know a simple if would suffice; but the keyword to this question is elegance. It's for my toy project not for production.
Edit 2: This questions wasn't about speed but about code beauty. Stop talking about efficiency and such; re...
Hey All,
I was just wondering if there's a way to generate many different combinations of numbers and letters, based off of just one number/letter? For example:
From just this one String:
234jk43fc7898cfg58
We could generate MANY different combos like:
HGYTD786Gjhghjg76fghf8
8976sgh8976
cv34905bv7
435bv4875bvg487bv
45b6467ne456n
4n5...
Synopsis
Post examples in any language of a type that represents integers without making direct use of machine integers. Include mappings to and from the user-defined type. Points for efficiency in space and/or time.
Original Question
In the comments of a certain rather bold answer to a question about object-oriented programming, I st...
So when I convert a double to a string using something like this:
double number = 1.1;
text = [[NSString alloc] initWithFormat:@"%f", number];
The variable text ends up printing something like this: 1.100000. I realize that this is because of the way the computer stores the value however I need an easy way to remove those extra zeros ...
Hi all,
I've tried to do a number(decimal) increment which looks like 001 002 003...123,124 in a loop and couldn't find a simple solution.What I've thought now is to check out whether the number is long enough ,if not prefix it some "0".But it seems not good.Any better ideas?
Thanks.
...
In Java, all numeric types extend from java.lang.Number. Would it be a good idea to have a method like the following:
public boolean areEqual(Number first, Number second) {
if (first != null && second != null) {
return first.equals(second);
}
}
I'm concerned about cases where a double 2.00000 does not equal an int 2. A...
I have a calendar and can make local month names and short weekday names, for example weekdaynames with:
NSArray *weekdayNames = [[[[NSDateFormatter alloc] init] autorelease] shortWeekdaySymbols];
How can I localize these?
For example:
a daycounter i = 1..31
daystr = [NSString stringWithFormat: @" %i", daycounter];}
I get fine 1....
This has been a programming problem which has interested me for a while.
You give the program a squence of numbers seperated by commas. It then finds a suitable formula from these numbers to find the next number in the sequence.
In: 1,2,3,4,5
Out: 6
In: 2,4,6,8
Out: 10
In: 10,8,6,4
Out: 2
I'm not sure if this problem is much more c...
I have code like:
lblFranshizShowInvwNoskhehEdit.Text = string.Format("{0:n}",
(double)(int.Parse(drDarman["FranshizDarsad"].ToString()) *
Convert.ToInt64(RadNumerictxtPayInvwNoskhehEdit.Text)) / 100);
But {0:n0} string format forces the label's text to not have decimal digits and {0:n} string format forces the label's te...
I need to display a file size as String using sensible units.
e.g.
1L ==> "1 B";
1024L ==> "1 KB";
2537253L ==> "2.3 MB"
etc.
I found this previous answer, which I didn't find satisfatory
I have come up with my own solution which has similar shortcomings:
private static final long K = 1024;
private static final long M = K * K;
pri...
Hello, how do I check if a string in a MySQL field contains a number then delete them?
Example table:
tbl_tags
-------------
| id | tag |
-------------
| 1 | hello |
| 2 | hello2 |
| 3 | 2hello |
| 4 | hel3lo |
-------------
The only way I can think of is to do each number individually and use LIKE '%1%' OR LIKE '%2%' etc....
Hello
I'm using a Java StreamTokenizer to extract the various words and numbers of a String but have run into a problem where numbers which include commas are concerned, e.g. 10,567 is being read as 10.0 and ,567.
I also need to remove all non-numeric characters from numbers where they might occur, e.g. $678.00 should be 678.00 or -87 ...
Hi guys,
This a very simple c question.
Is there a way to format a float for printf so that it has xx SIGNIFICANT decimals?
So I'm not take about, say, %5.3 float, but if I had
float x=0.00001899383
how would i output 0.0000189 if i wanted UP TO the first three non-zero decimals?
thanks! I'm not stating at home this weekend so I do...
How can I represent a given floating point number in hexadecimal form? For example,
60123,124;
...
Hi, I've been working on topcoder recently and I stumbled upon this question which I can't quite make understand.
The question is to find F(n) = f(1)+f(2)+....+f(n) for a given "n" such that f(n) is the largest odd divisor for n.
There are many trivial solutions for the answer; however, I found this solution very intriguing.
int comput...
for example we have two floating point numbers
task is calculate exponent diffrence or e_x-e_y what means exponent difference?
...