小编B. *_*ard的帖子

Python浮动到int转换

基本上,我将float转换为int,但我并不总是有预期的值.

这是我正在执行的代码:

x = 2.51

print("--------- 251.0")
y = 251.0
print(y)
print(int(y))

print("--------- 2.51 * 100")
y = x * 100
print(y)
print(int(y))

print("--------- 2.51 * 1000 / 10")
y = x * 1000 / 10
print(y)
print(int(y))

print("--------- 2.51 * 100 * 10 / 10")
y = x * 100 * 10 / 10
print(y)
print(int(y))

x = 4.02
print("--------- 402.0")
y = 402.0
print(y)
print(int(y))

print("--------- 4.02 * 100")
y = x * 100
print(y)
print(int(y))

print("--------- 4.02 …
Run Code Online (Sandbox Code Playgroud)

python floating-point int

63
推荐指数
4
解决办法
32万
查看次数

标签 统计

floating-point ×1

int ×1

python ×1