What you want is to set the 'scale' of the BigDecimal.

There doesn't seem to be a nice clojure macro for it, but this works:
    user=> (.setScale (reduce + [15.00M 15.01M 3.00M 3.01M]) 3)
    36.020M


---
Joseph Smith
j...@uwcreations.com
(402)601-5443





On Nov 29, 2009, at 2:02 PM, Gareth jones wrote:

> Agh that makes sense, I thought I was going crazy but I guess it's
> obvious now you point it out... Thanks for the help :D
>
> Gaz
>
> Sent from my iPhone
>
> On Nov 29, 2009, at 10:36 AM, Ahmed Fasih <wuzzyv...@gmail.com> wrote:
>
>> Hi, without knowing much about what's going on, note that
>>
>> user=> (reduce + [15.00M 15.01M 3.00M 3.01M])
>> 36.02M
>> user=> (with-precision 3 (reduce + [15.00M 15.01M 3.00M 3.01M]))
>> 36.0M
>>
>> So an intermediate step in the calculation is rounded down to 3
>> decimals and that rounding error is carried through. So the "9M" with
>> 3-precision would mean "9.00M".
>>
>> Amazing! It might be getting in your way here, but functions changing
>> their operation because they were called via "with-precision" speaks
>> to a flexibility that I've only seen in Lisps.
>>
>> On Nov 28, 10:27 pm, Gaz <gareth.e.jo...@gmail.com> wrote:
>>> Hi, apologies if this is a silly question. Im having some confusion
>>> with the following code:
>>>
>>> (with-precision 3 (/ 36.02M 4.00M))
>>> 9.01M
>>>
>>> This is what i would expect. This however:
>>>
>>> (with-precision 3 (/ (reduce + [15.00M 15.01M 3.00M 3.01M])
>>> 4.0M))
>>> 9M
>>>
>>> Seems a bit odd? Or am I missing something obvious :(
>>>
>>> Thanks for any help.
>>
>> --  
>> 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

-- 
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