This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-31
Channels
- # adventofcode (15)
- # announcements (8)
- # babashka (16)
- # beginners (48)
- # braveandtrue (5)
- # calva (54)
- # cider (7)
- # clara (8)
- # clj-kondo (3)
- # cljdoc (3)
- # clojure (37)
- # clojure-europe (1)
- # clojure-italy (15)
- # clojure-losangeles (2)
- # clojure-nl (15)
- # clojure-uk (6)
- # clojurescript (145)
- # community-development (53)
- # cursive (20)
- # data-science (8)
- # datomic (23)
- # duct (2)
- # emacs (22)
- # fulcro (16)
- # gorilla (7)
- # graalvm (7)
- # hoplon (1)
- # malli (7)
- # off-topic (8)
- # rewrite-clj (2)
- # ring (9)
- # spacemacs (2)
- # specter (1)
- # tools-deps (25)
- # vrac (1)
I tried to round a number yesterday and it was very frustrating, ended up using a string and then reconverting. How do you do it?
Forgive me if you're already aware, but depending on your needs you might not need to reach for a library like fastmath. Math/round
is from Java's standard library works for many use cases.
$ clj
Clojure 1.10.1
user=> (Math/round 0.7)
1
I use Apache Commons Math for that, but you can adapt the code from their strategies.
and here is the other strategy: https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/src-html/org/apache/commons/math3/util/Precision.html#line.426
Well, @slack.jcpsantiago or you can use the fastmath clojure library where @tsulej has already carefully gone through a bunch of libraries and curated the fastest paths out of them for various forms of arithmetic: https://github.com/generateme/fastmath