Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I divide numbers in clojure I get a fraction , how do I get the decimal?

When I do (/ 411 125) , I don't get it in terms of decimal. How do I do that?

like image 349
unj2 Avatar asked Oct 20 '09 18:10

unj2


People also ask

How do you round in Clojure?

One of the simplest ways to "round" numbers is truncation. int will do this for you, coercing floating-point numbers to integers by simply chopping off any trailing decimal places.


2 Answers

user> (float (/ 411 125)) 3.288 user> (double (/ 411 125)) 3.288 
like image 148
Brian Carper Avatar answered Oct 07 '22 03:10

Brian Carper


user=> (clojure-version) "1.4.0"  user=> (doc quot) ------------------------- clojure.core/quot ([num div])   quot[ient] of dividing numerator by denominator. nil  user=> (quot 411 125) 3 
like image 40
Jacek Laskowski Avatar answered Oct 07 '22 05:10

Jacek Laskowski