[英]getting the number of decimal places of a float python
How can I write a function that show how many decimal places each float-3
value has.我如何编写一个 function 来显示每个
float-3
值有多少个小数位。 How would I be able to get that?我怎么能得到那个?
float1= 4.9778
float2 = 6.9987475673579
float3= 4567.1
Expected output:预期 output:
4
13
1
You should not use float as a variable name.您不应该使用 float 作为变量名。 You will be unable to use it if you want to create a float variable.
如果您想创建一个浮点变量,您将无法使用它。 Your problem is easy to solve.
你的问题很容易解决。 Just use this:
只需使用这个:
num = 124.178
tmp = len(str(num).split(".")[1])
print(tmp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.