繁体   English   中英

将浮点数扩展到多余的小数位

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM