[Cubicweb] Float / Decimal CW Data types

Carlos Balderas carlos.balderas at gmail.com
Mon Dec 13 16:39:35 CET 2010


Adrien, thank you for this very detail explanation.

Thanks a lot for your support.

Regards
Carlos Balderas

On Mon, Dec 13, 2010 at 1:48 AM, Adrien Di Mascio <
adrien.dimascio at logilab.fr> wrote:

> Hi Carlos,
>
>
> On 13/12/2010 00:51, Carlos Balderas wrote:
>
>> Would  you please give me an advise about when to use Float or Decimal
>> in Cubicweb.
>>
>
> The answer is the same as it would be in Python. Use Decimal if you need to
> perform exact calculations (e.g banking, payroll applications). In other
> cases, standard floating point arithmetic should suit your needs, and Float
> is probably the best choice, it's faster (both in SQL and in Python) and
> probably more convenient.
>
> From a SQL point of view, Decimal attributes are converted to ``DECIMAL``
> sql type (or NUMERIC, I believe they're equivalent) whereas Float attributes
> will use ``FLOAT``.
>
> In Python, Decimal attributes will be deserialized with the
> ``decimal.Decimal`` type, Float attributes will use the standard float type.
>
> I would suggest you to read, if you havent' done yet, the documentation
> of the ``decimal`` stdlib module :
>
>   http://docs.python.org/library/decimal.html
>
>
>  When displaying decimal attributes in form creation/edition, the input
>> box's size looks like the size of a "text" value, making a little bit of
>> confusion at first sight at the time to capture the values, IMHO.
>>
>
> I don't have any strong opinion on this. However, our implementation of
> Decimal is a bit incomplete : we should be able to specify a precision for
> decimal values. e.g. :
>
>  debt = Decimal(precision=15, scale=12)
>
> In that case, the input field in form should adapt to the precision
> specified in the schema.
>
> See
>
> http://www.postgresql.org/docs/8.4/interactive/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL
>
> Regards,
> --
> Adrien Di Mascio - LOGILAB, Paris (France).
> Tél: 01.45.32.03.12
> Formations - http://www.logilab.fr/formations
> Développements - http://www.logilab.fr/services
> Gestion de connaissances - http://www.cubicweb.org/
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20101213/53cc89a3/attachment.htm>


More information about the Cubicweb mailing list