Skip to content

Python decimal to float conversion

  • by

Just use the float() function to convert decimal to float in Python. Or you can use float_number = decimal_number * 1.0 formula.

number_in_float = float(number_you_have)

Python decimal to float example

Simple example code. (dec * decimal.Decimal(1.0)) is not working for us.

import decimal

dec = decimal.Decimal('10')
print(dec)
print(type(dec))

f = float(dec)
print(f)
print(type(f))

res = (dec * decimal.Decimal(1.0))
print(res)

Output:

Python decimal to float example

Do comment if you have any doubts or suggestions on this Python conversion topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading