What's the easiest way to parse numbers in clojure?

后端 未结 10 1593
长发绾君心
长发绾君心 2020-12-08 09:30

I\'ve been using java to parse numbers, e.g.

(. Integer parseInt  numberString)

Is there a more clojuriffic way that would handle both int

10条回答
  •  醉酒成梦
    2020-12-08 09:51

    If you want to be safer, you can use Float/parseFloat

    user=> (map #(Float/parseFloat (% 0)) (re-seq #"\d+(\.\d+)?" "1 2.2 3.5"))
    (1.0 2.2 3.5)
    user=> 
    

提交回复
热议问题