Python: Remove division decimal

前端 未结 7 2082
予麋鹿
予麋鹿 2020-12-29 21:05

I have made a program that divides numbers and then returns the number, But the thing is that when it returns the number it has a decimal like this:

2.0
         


        
7条回答
  •  长发绾君心
    2020-12-29 21:19

    There is a math function modf() that will break this up as well.

    import math
    
    print("math.modf(3.14159) : ", math.modf(3.14159))
    

    will output a tuple: math.modf(3.14159) : (0.14159, 3.0)

    This is useful if you want to keep both the whole part and decimal for reference like:

    decimal, whole = math.modf(3.14159)

提交回复
热议问题