用string-python

时间:2016-07-08 16:43:29

标签: python

我想用字符串

替换浮点中的点

例如,如果我有一个浮点数15.444,我需要打印它,如下面的15个鸡蛋444鸡

如果我采取一个真实的例子,这里是代码

enter code here

name = "chris"
height_cm = 175
height = (height_cm * 1/2.54) * 1/12 
weight = 79


print "He is %s" % name
print "His height is %.2f" %height, "inches" 
print "His weight is %d" % weight

第二条打印线将输出"我的高度为5.7英寸"这里我该如何替换"。"用一根绳子。在这种情况下,我需要更换"。"用字符串"脚"

++++++++++++++++++输出++++++++++++++++++++++++ 他是克里斯 他的身高是5.7英寸 他的体重是79 +++++++++++++++++++输出+++++++++++++++++++++++

1 个答案:

答案 0 :(得分:-2)

我不编写python代码,但你可能想要按照这个(java)的方式做一些事情:

float input = 15.444f;
int[] split = (input+"").split(".");
System.out.println(split[0]+" eggs and "+split[1]+" chickens");

但为什么你需要做这样的事情。浮点数是2个整数值的可怕存储方法。请尝试使用数组。