嗨,您能否参考下面的示例代码,让我知道 round 和 int 函数之间的确切区别 OUTPUT:12 美元和 0 美分 12 美元和 1.0 美分
# code is to convert xx.yy to xx dollars and yy cents **
val = 12.01
dollars = int(val) #Integer value to know how many Dollars
cents = int(100 * (val - dollars)) #Integer value to know how many cents
print str(dollars) + " dollars and " + str(cents) + " cents"
如果我用圆形函数编写相同的代码,我会得到正确的答案
val = 12.01
dollars = int(val) #Integer value to know how many Dollars
cents = round(100 * (val - dollars)) #Integer value to know how many cents
print str(dollars) + " dollars and " + str(cents) + " cents"
不知道为什么当我使用 int 时它显示为 0 美分。