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:
mdb
2006-01-18 18:29:28 +00:00
parent 4ee768e50e
commit a210fb8dab
@@ -45,6 +45,15 @@ public class DataTool
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.
*/