Display a float with two decimal places in Python

前端 未结 11 2256
我在风中等你
我在风中等你 2020-11-22 14:36

I have a function taking float arguments (generally integers or decimals with one significant digit), and I need to output the values in a string with two decimal places (5

11条回答
  •  梦谈多话
    2020-11-22 14:56

    If you want to get a floating point value with two decimal places limited at the time of calling input,

    Check this out ~

    a = eval(format(float(input()), '.2f'))   # if u feed 3.1415 for 'a'.
    print(a)                                  # output 3.14 will be printed.
    

提交回复
热议问题