couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hahn <m...@reevuit.com>
Subject Re: decimal and builtin _sum function
Date Fri, 15 Nov 2013 16:28:35 GMT
> I store the numbers as strings because I read this the proper way for
decimals.

Where did you read this?  That makes no sense.


On Fri, Nov 15, 2013 at 4:27 AM, Robert Newson <rnewson@apache.org> wrote:

> "I store the numbers as strings because I read this the proper way for
> decimals."
>
> You'll need a custom library to handle such strings. The article you
> read is just pointing out that a string will not be modified or
> interpreted in any way, which is the property you seek. But you'll
> need a multiprecision library that understands strings of that form to
> be able to process them.
>
> B.
>
>
>
> On 15 November 2013 12:19, Pedro Narciso García Revington
> <p.revington@gmail.com> wrote:
> > Yes, I know this is not couchdb stuff. What confused to me was to store
> > numbers as  strings.
> >
> >
> > 2013/11/15 Robert Newson <rnewson@apache.org>
> >
> >> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message