Hi Pedro,

On Fri, Nov 15, 2013 at 10:29 AM, Pedro Narciso García Revington
<p.reving...@gmail.com> wrote:
> Hi,
>
> I want to sum decimals with the builtin _sum function.
> My documents look like
> {
>    "_id": "7a2c5e50dfeb1341d02aa27c7a05f629",
>    "_rev": "4-482ff2f6b6e5c2aa079e3e4114d02093",
>    "type": "payment",
>    "amount": "0.2"
> }
> I store the numbers as strings because I read this the proper way for
> decimals.

I would echo Stefan's suggestion in this case since you're dealing
with adding "money" numbers.  Otherwise, you have to deal with normal
numerical rounding issues when performing operations on floats.

>
> If I try to sum them with the builtin _sum I get the following error
> "builtin _sum function requires map values to be numbers"
>
> I removed the quotes from the numbers. Now I can sum them but 0.2 + 0.1
> equals to 2.99999999

Was this a typo?  Did you mean 0.2999999 ?

Cheers,
Mike

Reply via email to