Thanks Ken. That did the trick.

-----Original Message-----
From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of 
Ken Wesson
Sent: Friday, June 17, 2011 3:17 PM
To: clojure@googlegroups.com
Subject: Re: BigDecimal Division - Arithmetic Exception

On Fri, Jun 17, 2011 at 2:51 PM, Bhinderwala, Shoeb
<sabhinderw...@wellington.com> wrote:
> What is the workaround in Clojure for:
>
>   (/ 1M 3M)
>
> I am reading data from the database which by default comes in as BigDecimal
> (through the JDBC driver and Clojure SQL). When I perform calculations on
> them including division with the '/' operator I get frequent
> ArithmeticExceptions based on my data.
>
> How should I deal with this? Also does it mean that performing division is
> not safe on data read from the database due to this problem?

Pick a finite precision sufficient for your needs and wrap in
(with-precision ...).

Take care about returning lazy sequences containing bignum division
results though; you may need to use the odd (doall ...) to force
sequences before they leave the scope of the with-precision.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to