I needed a function to get the percentage as an int. Input is place and total-count. I want the normal definition (which is the default) and a high and low variant.
I came up with the following code: (defn get-percentage ([place total-count] (get-percentage :normal place total-count)) ([mode place total-count] (let [percentage (/ (* place 100.0) total-count)] (condp = mode :high (int (Math/ceil percentage)) :low (int (Math/floor percentage)) :normal (int (Math/round percentage)) (throw (Exception. "ERROR: get-percentage [:high|:low|:normal] <PLACE> <TOTAL_COUNT>")))))) Is this a good version, or could it be done better? -- Cecil Westerhof -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.