How do I get a decimal value when using the division operator in Python?

前端 未结 13 2026
旧巷少年郎
旧巷少年郎 2020-12-01 06:18

For example, the standard division symbol \'/\' rounds to zero:

>>> 4 / 100
0

However, I want it to return 0.04. What do I use?

13条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 06:41

    You cant get a decimal value by dividing one integer with another, you'll allways get an integer that way (result truncated to integer). You need at least one value to be a decimal number.

提交回复
热议问题