Fork me on GitHub
#data-science
<
2019-12-31
>
Santiago10:12:35

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?

zane00:01:22

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

genmeblog11:12:53

I use Apache Commons Math for that, but you can adapt the code from their strategies.

chrisn14:12:12

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

genmeblog15:12:52

haha, yes, fastmath exposes what I've mentioned above as round, rint, and approx

Santiago16:12:25

Nice thank you both, I'll check it out