相关疑难解决方法(0)

如何用Python舍入到2位小数?

我在这段代码的输出中得到了很多小数(华氏温度到摄氏温度转换器).

我的代码目前看起来像这样:

def main():
    printC(formeln(typeHere()))

def typeHere():
    global Fahrenheit
    try:
        Fahrenheit = int(raw_input("Hi! Enter Fahrenheit value, and get it in Celsius!\n"))
    except ValueError:
        print "\nYour insertion was not a digit!"
        print "We've put your Fahrenheit value to 50!"
        Fahrenheit = 50
    return Fahrenheit

def formeln(c):
    Celsius = (Fahrenheit - 32.00) * 5.00/9.00
    return Celsius

def printC(answer):
    answer = str(answer)
    print "\nYour Celsius value is " + answer + " C.\n"



main()
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,如何使程序围绕小数点后两位的每个答案?

python rounding

179
推荐指数
14
解决办法
50万
查看次数

标签 统计

python ×1

rounding ×1