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
haha, yes, fastmath
exposes what I've mentioned above as round
, rint
, and approx
Nice thank you both, I'll check it out