Thanks so much for your answers. OK. So from the solutions above I understand that Clojure does not have C#'s equivalent of Math.round(7.127298, 2), and requires either using some custom method or Java's rounding?
I think I'll rather go with the Java-interop approach. On Mar 23, 11:13 pm, Joost <jo...@zeekat.nl> wrote: > 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