diff --git a/projects/samskivert/src/java/com/samskivert/velocity/DataTool.java b/projects/samskivert/src/java/com/samskivert/velocity/DataTool.java index 81a2202e..650271d0 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/DataTool.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/DataTool.java @@ -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. */