On Mar 23, 8:07 pm, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > 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…
Most important one being that it won't be reliable. Floats are fundamentally not compatible with decimal rounding. You'll have to switch to some other representation like (big) decimals, fixed point or strings to get it. -- 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