I'm trying to create an octal handling function in Clojure, so far I have this:
(defn octal [a]
(if (= 023 a)
(Integer/toOctalString a)
a))
where I have '023' i would like to replace it with some logic which checks if a number begins with '0'. I'm aware of starts-with? for strings, is there a method for use with numbers?
I'm trying to do it this way as if I pass Integer/toOctalString an integer without a 0 it passes back a larger number. E.g. 2345 becomes 4451.
Thank you
It seems
read-string
can do this for you:If you want to read octal without prefix you can simply add the zero before passing it: