for with decimal values?

Esmail ebonak at hotmail.com
Sat May 2 21:31:38 EDT 2009


Ben Finney wrote:
> 
> Note that those values are of type ‘float’, which is a distinct type
> from ‘Decimal’ with very different behaviour.
> 
>> If there is such a thing already available, I'd like to use it,
>> otherwise I can write a function to mimic this, but I thought I'd
>> check (my search yielded nothing).
> 
> You can write a function to do it.
> 
> Alternatively, this case seems simple enough that you can write a
> generator expression. Assuming you want ‘Decimal’ values:
> 
>     >>> from decimal import Decimal
>     >>> amounts = (Decimal(mantissa)/10 for mantissa in range(-105, 105))
>     >>> for amount in amounts:
>     ...     print amount
>     ...


Another nice solution stored away for use!

Thanks,
Esmail




More information about the Python-list mailing list