Automatic Type Conversion in Clojure

less than 1 minute read

Code

;; automatic_type_casting.clj

42
(type 42)
(type 42.5)
(+ 42 42.5)
(type (+ 42 42.5))
42.7M
(type 42.7M)
(+ 42.5 42.7M)
(type (+ 42.5 42.7M))
(type (+ 42 42.0))

(type 994824757458783748579437258798745.278375725925479247582945754M)

(type (+ 1
   994824757458783748579437258798745.278375725925479247582945754M))

(str 42)

(str 42 " is the ultimate answer")

(Integer/parseInt "42")

(type (Integer/parseInt "42"))

(type (
  + (Integer/parseInt "42") 42))

(Double/parseDouble "42.5")

(Integer/parseInt "42")

(Integer/parseInt 42.5)

Updated: