I was bitten by this a year ago and posted here:
http://groups.google.com/group/clojure/browse_frm/thread/9091ad790fc96b24
My workaround is to call BigDecimal#stripTrailingZeros before passing
it to code that might compare it to some other number.
user> (== 1 (.stripTrailingZeros 1.0M))
true
However, there is an edge case:
user> (== 0 (.stripTrailingZeros 0.0M))
false
Which is due to this Java bug:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6480539
So I use a function like the following instead of bigdec to parse
BigDecimals.
(defn parse-stripped-bigdec [^String value-str]
;; Note that bigdec uses reflection (at least in Clojure 1.2.1)
(let [n (java.math.BigDecimal. value-str)]
(if (zero? n) 0M (.stripTrailingZeros n))))
Be aware that stripping the zeros changes how the BigDecimal is
formatted by #toString.
user> (str (parse-stripped-bigdec "10"))
"1E+1"
So, I have a special case for BigDecimal that calls #toPlainString in
the places where I do not want exponential format.
user> (.toPlainString (parse-stripped-bigdec "10"))
"10"
I hope that helps.
- Pat