我不是最好的程序员,但我正在计算点钞计划。我试图让我的程序将浮点数舍入到两个小数位而不会在运行它时发生这种情况:
How many $100 do you have
0
How many $50 do you have
0
How many $20 do you have
4
How many $10 do you have
1
How many $5 do you have
14
How many $2 do you have
1
How many $1 do you have
4
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000004444444444
444444444411111111111414141414114
P.S。我还没做分数
P.s.s圆函数剂量也起作用 正如我所想的那样
这是我的编码:
#Bill Parts
print "How many $100 do you have"
hundred_bill = raw_input('')
hundred_billone = hundred_bill * 100
#======================================================================
print "How many $50 do you have"
fifty_bill = raw_input('')
fifty_billone = fifty_bill * 50
#======================================================================
print "How many $20 do you have"
twenty_bill = raw_input('')
twenty_billone = twenty_bill * 20
#======================================================================
print "How many $10 do you have"
ten_bill = raw_input('')
ten_billone = ten_bill * 10
#======================================================================
print "How many $5 do you have"
five_bill = raw_input('')
five_billone = five_bill * 5
#======================================================================
print "How many $2 do you have"
two_bill = raw_input('')
two_billone = two_bill * 2
#======================================================================
print "How many $1 do you have"
one_bill = raw_input('')
one_billone = one_bill * 1
#======================================================================
#======================================================================
#======================================================================
#Cent Parts
#======================================================================
bills = hundred_billone + fifty_billone + twenty_billone + ten_billone +
five_billone + two_billone + one_billone
print bills
答案 0 :(得分:2)
在python 2和3中,你可以将。十倍()一个Decimal调到你想要的任何精度:
setContentView (R. layout. example);