No need.  The Python tutorial says mixing integers and decimals in
arithmetic is OK.

Note version 2.7.1 in the following.

cjk@mid-tower:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> foo = Decimal('1.5')
>>> foo + 2
Decimal('3.5')

And here is why one should not use float for currency:
>>> bar = float(3.14)
>>> bar + 2
5.140000000000001
>>> fooble = float('3.14')
>>> fooble + 2
5.140000000000001

An alternative way to do math with currency is multiply everything by
1000 and do integer math on the results.
Just remember to do the appropriate division for output to views.



On Dec 1, 6:19 pm, pbreit <pbreitenb...@gmail.com> wrote:
> Great info, thanks.
>
> I hadn't thought of using Decimal type for integers that might be involved
> in calculations. Can I simulate an integer with something like
> "decimal(4,0)"? For quantity, I'd rather show "1" and not "1.0".

Reply via email to