[Python-ideas] Python Float Update

Terry Reedy tjreedy at udel.edu
Tue Jun 2 00:26:46 CEST 2015


On 6/1/2015 10:52 AM, Joonas Liik wrote:
> Having some sort of decimal literal would have some advantages of its
> own, for one it could help against this sillyness:
>
>  >>> Decimal(1.3)
> Decimal('1.3000000000000000444089209850062616169452667236328125')
>
>  >>> Decimal('1.3')
> Decimal('1.3')
>
> I'm not saying that the actual data type needs to be a decimal (
> might well be a float but say shove the string repr next to it so it can
> be accessed when needed)
>
> ..but this is one really common pitfall for new users, i know its easy
> to fix the code above,
> but this behavior is very unintuitive.. you essentially get a really
> expensive float when you do the obvious thing.
>
> Not sure if this is worth the effort but it would help smooth some
> corners potentially..

Since Decimal is designed specifically for money calculations, $ could 
be used as a generic money suffix.
1.3$ == Decimal(1.3)
.0101$ (money multiplier, as with interest)


-- 
Terry Jan Reedy



More information about the Python-ideas mailing list