Skip to content
Snippets Groups Projects
Commit 37e8467e authored by Allen Gilliland's avatar Allen Gilliland
Browse files

couple fixes for zero comparison.

parent 9ae7c238
No related branches found
No related tags found
No related merge requests found
......@@ -122,7 +122,7 @@
(let [decimal-type? #(or (float? %) (decimal? %))]
(cond
;; looks like this is a decimal number, format with precision of 2
(and (decimal-type? number) (not= 0 (mod number 1))) (format "%,.2f" number)
(and (decimal-type? number) (not (zero? (mod number 1)))) (format "%,.2f" number)
;; this is a decimal type number with no actual decimal value, so treat it as a whole number
(decimal-type? number) (format "%,d" (long number))
;; otherwise this is a whole number
......
......@@ -48,22 +48,32 @@
;; ## tests for `(format-num)`
;; basic whole number case
(expect "1" (format-num 1))
(expect "1" (format-num (float 1)))
(expect "1" (format-num (double 1)))
(expect "1" (format-num (bigdec 1)))
(expect "1" (format-num (long 1)))
;; make sure we correctly format down to 2 decimal places
;; note that we are expecting a round DOWN in this case
(expect "1.23" (format-num (float 1.23444)))
(expect "1.23" (format-num (double 1.23444)))
(expect "1.23" (format-num (bigdec 1.23444)))
;; test that we always force precision of 2 on decimal places
(expect "1.20" (format-num (float 1.2)))
(expect "1.20" (format-num (double 1.2)))
(expect "1.20" (format-num (bigdec 1.2)))
;; we can take big numbers and add in commas
(expect "1,234" (format-num 1234))
(expect "1,234" (format-num (float 1234)))
(expect "1,234" (format-num (double 1234)))
(expect "1,234" (format-num (bigdec 1234)))
(expect "1,234" (format-num (long 1234)))
(expect "1,234.56" (format-num (float 1234.5678)))
(expect "1,234.56" (format-num (double 1234.5678)))
(expect "1,234.56" (format-num (bigdec 1234.5678)))
;; we can handle numbers with both commas and decimal places
;; note that we expect a basic round UP here
(expect "1,234.57" (format-num (float 1234.5678)))
(expect "1,234.57" (format-num (double 1234.5678)))
(expect "1,234.57" (format-num (bigdec 1234.5678)))
;;; ## tests for IS-URL?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment