Last active
January 6, 2022 20:07
-
-
Save quoll/f0973d878a9339220cdd3ebafef229d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as string]) | |
(defn f | |
[n] | |
(let [s (str n)] | |
(js/parseFloat | |
(if-let [[[_ a b]] (re-seq #"(\d*)\.(\d*)" (if (string/starts-with? s "0") (subs s 1) s))] | |
(let [al (- (count a) 3)] | |
(if (> al 0) | |
(str (subs a 0 al) "." (subs a al) b) | |
(str (apply str "0." (repeat (- al) "0")) (when-not (= "0" a) a) b))) | |
(let [nl (- (count s) 3)] | |
(str (subs s 0 nl) "." (subs s nl))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment