How to convert Decimal() to a number in Python?
Question: I have a JSON output that is `Decimal('142.68500203')`.

I can use str() to get a string which is `"142.68500203"`. But I want to get a
number output which is `142.68500203`.

How to make the conversion in Python?


Answer: It depends what you mean by "number", it could be argued that `Decimal` is a
number class. If you mean into an object of `float` class then:

    
    
    from decimal import Decimal
    
    x = Decimal('142.68500203')
    
    y = float(x)
    
    print x, y
    

Gives:

    
    
    142.68500203 142.68500203
    

But beware! There are good reasons for using `Decimal`, read [the Decimal
documentation](https://docs.python.org/2/library/decimal.html) before deciding
you want `float`.

