diff options
Diffstat (limited to 'src/clojure')
-rw-r--r-- | src/clojure/contrib/pprint/cl-format.clj | 28 | ||||
-rw-r--r-- | src/clojure/contrib/test_contrib/pprint/cl_format.clj | 8 |
2 files changed, 22 insertions, 14 deletions
diff --git a/src/clojure/contrib/pprint/cl-format.clj b/src/clojure/contrib/pprint/cl-format.clj index b0531c14..6fd691e2 100644 --- a/src/clojure/contrib/pprint/cl-format.clj +++ b/src/clojure/contrib/pprint/cl-format.clj @@ -575,19 +575,21 @@ Note this should only be used for the last one in the sequence" [(str "0" m) (inc e) 1 (inc len)] [m e round-pos len])] (if round-pos - (if (> len round-pos) - (let [round-char (nth m1 round-pos) - #^String result (subs m1 0 round-pos)] - (if (>= (int round-char) (int \5)) - (let [result-val (Integer/valueOf result) - leading-zeros (subs result 0 (min (prefix-count result \0) (- round-pos 1))) - round-up-result (str leading-zeros - (String/valueOf (+ result-val - (if (neg? result-val) -1 1)))) - expanded (> (count round-up-result) (count result))] - [round-up-result e1 expanded]) - [result e1 false])) - [m e false]) + (if (neg? round-pos) + ["0" 0 false] + (if (> len round-pos) + (let [round-char (nth m1 round-pos) + #^String result (subs m1 0 round-pos)] + (if (>= (int round-char) (int \5)) + (let [result-val (Integer/valueOf result) + leading-zeros (subs result 0 (min (prefix-count result \0) (- round-pos 1))) + round-up-result (str leading-zeros + (String/valueOf (+ result-val + (if (neg? result-val) -1 1)))) + expanded (> (count round-up-result) (count result))] + [round-up-result e1 expanded]) + [result e1 false])) + [m e false])) [m e false])) [m e false])) diff --git a/src/clojure/contrib/test_contrib/pprint/cl_format.clj b/src/clojure/contrib/test_contrib/pprint/cl_format.clj index 6684bff2..6c73e63f 100644 --- a/src/clojure/contrib/test_contrib/pprint/cl_format.clj +++ b/src/clojure/contrib/test_contrib/pprint/cl_format.clj @@ -188,7 +188,13 @@ (cl-format nil "~1,1,8,' @:$" -12.0) "- 12.0" (cl-format nil "~1,1,8,' @$" -12.0) " -12.0" (cl-format nil "~1,1,8,' :$" -12.0) "- 12.0" - (cl-format nil "~1,1,8,' $" -12.0) " -12.0") + (cl-format nil "~1,1,8,' $" -12.0) " -12.0" + (cl-format nil "~1,1$" 0.001) "0.0" + (cl-format nil "~2,1$" 0.001) "0.00" + (cl-format nil "~1,1,6$" 0.001) " 0.0" + (cl-format nil "~1,1,6$" 0.0015) " 0.0" + (cl-format nil "~2,1,6$" 0.005) " 0.01" + (cl-format nil "~2,1,6$" 0.01) " 0.01") (simple-tests f-tests (cl-format nil "~,1f" -12.0) "-12.0") |