a bit naive, but it seems to work…
user=> (defn round
[x & {p :precision}]
(if p
(let [scale (Math/pow 10 p)]
(-> x (* scale) Math/round (/ scale)))
(Math/round x)))
#'user/round
user=> (round 78.37898794)
78
user=> (round 78.37898794 :precision 3)
78.379
There are probably thousand reasons not to do that…
Sincerely
Meikel
(defn round [s n]
(.setScale (bigdec n) s java.math.RoundingMode/HALF_EVEN))
#'user/round
user=> (round 3 (/ 1 3))
ArithmeticException Non-terminating decimal expansion; no exact representable decimal result. java.math.BigDecimal.divide (BigDecimal.java:1603)