-
Member
Quick Java Division fix
Hi guys...
I'm doing static task allocation - need to divide a task into iterations.
I have a long, which is the total iterations, and want to divide by 3 for three nodes.
Problem is, how to round up/down to make sure I only get whole numbers?
Was thinking something like this:
long totalIterations = <a number>;
long chunk = totalIterations/3;
long chunk1 = chunk.roundUp();
long chunk2 = chunk.roundUp();
long chunk3 = totalIterations - (chunk1+chunk2);
So does anyone know of a method for rounding up (or down) a long with decimal places?
Thanks!
-
Member
Goddamn I'm dumb...
Math.round, perhaps?
meh.
I'd been looking in the java.math package... it never occurred to me (ever!) that there was a Math object...
ah well... I live (barely) and learn (eventually)!
-
Ultimate Member
rounding is easily done using
Code:
return new Integer(long+0.5).intValue();
. Thats all the Math.round function does (logic been an int value just cuts the decimals off therefore 0.2+0.5 = 0, but 0.7+0.5 = 1).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|