incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: decimal and builtin _sum function
Date Fri, 15 Nov 2013 12:08:15 GMT
Ah, sure. If you're using floating point to store (or compute on)
money values you've committed a sin (I used to work in accounting
software, this is the one thing you do not do, besides looking for a
job not involving accounting software).

We've had a few threads on number handling in the past and it gets
complicated. Javascript really only has 64-bit floating point numbers
in practice. Our JSON encoder/decoder will retain the precision of
your input values but does not guarantee it will preserve the
representation.

If I were writing accounting software with CouchDB, I would be storing
my money values as an object of three strings like
{"amount":"200","dp":"2","currency":"USD"}, which represents $2. I
would then perform all calculations in custom code, not being prepared
to trust the various oddnesses of Javascript.

Read https://issues.apache.org/jira/browse/COUCHDB-1410 for more fun.

B.


On 15 November 2013 11:55, Pedro Narciso GarcĂ­a Revington
<p.revington@gmail.com> wrote:
> Yes, I'm dealing with money but also with micro decrements (cost per
> impression on ads).
> So my decrements are going to be like 0.000123.
> I think what I'm going to do is to sum them before push them into couchdb
> so I do not need to deal with decimals.
>
>
>
> 2013/11/15 Mike Marino <mmarino@gmail.com>
>
>> > To answer the original question, _sum can only sum numbers, it does
>> > not understand numbers inside strings.
>> >
>>
>> The way I understood the OP's question was that he had correctly,
>> following the error message, converted to using numbers instead of
>> strings, but then didn't understand the obtained result.
>>
>>
>> >> sidenote: super cool talk by Bartek Szopka about floating point numbers
>> in
>> >> JavaScript (and other languages) held at JSConf.eu 2013
>> >>
>> >> https://www.youtube.com/watch?v=MqHDDtVYJRI
>>
>> This is interesting, nice.  I come from a background where numerical
>> precision and memory layout is often a concern (e.g. physics
>> simulations, hardware readout), but these types of things I think can
>> be more easily forgotten when using higher level languages like
>> javascript, python, etc.  Imo it's still an essential understanding to
>> have.
>>

Mime
View raw message