[英]How to fix floating point decimal to two places even if number is 2.00000
[英]Extending A Floating Point Number to Extra Decimal Places
因此,在我的初學者python類中,我們被要求對用戶鍵入的數字(基本內容)執行一些基本的算術運算。 本來應該返回一個小數點后兩位的數字,但是我只能將其擴展為一個。 如果小數點在第一個小數點處終止,是否可以添加另一個位置? 如果小數點以后終止或為無窮小,是否也可以顯示第二個數字?
print "Please enter the month of your birthday as a number.";
print "\t Jan = 1";
print "\t Feb = 2";
print "\t Apr = 3"
print "etc, etc, etc."
num = input("\n");
day = input("What date were you born on?\n");
new = (((((((((((num * 7.0) - 1.0) * 13.0) + day) + 3.0) * 11.0) - num) - day) / 10.0) + 11.00) / 100.0);
print "You were born in the", new, "month.";
只是需要做一點實驗,我的解決方案有點作弊。
new = str(new) + "0";
這會將“ new”更改為字符串,並向浮點數添加額外的0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.