# [Cubicweb] Float / Decimal CW Data types

Mon Dec 13 08:48:13 CET 2010

```Hi Carlos,

On 13/12/2010 00:51, Carlos Balderas wrote:
> 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/

```