Added percent() which also handles 0/0.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1763 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -45,6 +45,15 @@ public class DataTool
|
|||||||
return (array == null) ? 0 : Array.getLength(array);
|
return (array == null) ? 0 : Array.getLength(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the numerator as a percentage of the denominator (100 * num /
|
||||||
|
* denom), handles 0/0 (returns 0), but will div0 on N/0 where N != 0.
|
||||||
|
*/
|
||||||
|
public int percent (int num, int denom)
|
||||||
|
{
|
||||||
|
return (num == 0) ? 0 : 100 * num / denom;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Floating point divide.
|
* Floating point divide.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user