How to convert int to float in python?

前端 未结 6 1148
慢半拍i
慢半拍i 2020-12-29 21:39

Does anyone know how to convert int to float.

For some reason, it keeps on printing 0. I want it to print a specific decimal.



        
6条回答
  •  别那么骄傲
    2020-12-29 22:30

    You can literally convert it into float using:

    
    float_value = float(integer_value)
    
    

    Likewise, you can convert an integer back to float datatype with:

    
    integer_value = int(float_value)
    
    

    Hope it helped. I advice you to read "Build-In Functions of Python" at this link: https://docs.python.org/2/library/functions.html

提交回复
热议问题