题解 | #牛牛的小数输出#
牛牛的小数输出
https://www.nowcoder.com/practice/0454d1bd28cd499ba06afdabe0fb9caf
print("{:.2f}".format(float(input())))
解析如下:
str.format() 格式化数字方法:
例如:
>>> print("{:.2f}".format(3.1415926)) 3.14
数字 | 格式 | 输出 | 描述 |
---|---|---|---|
3.1415926 | {:.2f} | 3.14 | 保留小数点后两位 |
例如:
x = float(8) # x 输出结果为 8.0 y = float(5.6) # y 输出结果为 5.6 z = float("47") # z 输出结果为 47.0
Python3.x 中 input() 函数接受一个标准输入数据,返回为 string(字符串) 类型。