[Cubicweb] Float / Decimal CW Data types

Adrien Di Mascio adrien.dimascio at logilab.fr
Mon Dec 13 08:48:13 CET 2010

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 :


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


Adrien Di Mascio - LOGILAB, Paris (France).
Formations - http://www.logilab.fr/formations
Développements - http://www.logilab.fr/services
Gestion de connaissances - http://www.cubicweb.org/

More information about the Cubicweb mailing list