Skip to content

Commit

Permalink
Fixed an issue with BigDecimal numbers throwing an exception when the…
Browse files Browse the repository at this point in the history
…y can't express a number as a decimal.
  • Loading branch information
macourtney committed Jul 16, 2011
1 parent 1b93113 commit 8e1a1db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject darkexchange "1.0.0-BETA4"
(defproject darkexchange "1.0.0"
:description "Dark Exchange is a distributed p2p exchange for bitcoin."
:dependencies [[clojure-tools "1.0.0"]
[com.h2database/h2 "1.3.157"]
Expand Down
10 changes: 7 additions & 3 deletions src/darkexchange/model/offer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[darkexchange.model.payment-type :as payment-type]
[darkexchange.model.user :as user])
(:use darkexchange.model.base)
(:import [java.util Date]))
(:import [java.math RoundingMode]
[java.util Date]))

(def offer-add-listeners (atom []))
(def delete-offer-listeners (atom []))
Expand Down Expand Up @@ -125,11 +126,14 @@
(defn reopen-offer [offer]
(update { :id (:id offer) :closed 0 }))

(defn big-decimal-divide [numerator denominator]
(.divide (bigdec numerator) denominator 8 RoundingMode/HALF_UP))

(defn calculate-has-div-wants [offer]
(/ (:has_amount offer) (:wants_amount offer)))
(big-decimal-divide (:has_amount offer) (:wants_amount offer)))

(defn calculate-wants-div-has [offer]
(/ (:wants_amount offer) (:has_amount offer)))
(big-decimal-divide (:wants_amount offer) (:has_amount offer)))

(defn convert-to-table-offer [offer]
{ :id (:id offer)
Expand Down

0 comments on commit 8e1a1db

Please sign in to comment.