jf3*_*328 8 python string.format
是否有格式选项,以便
>>> '%.1(format)'%2.85
Run Code Online (Sandbox Code Playgroud)
给出'2.8'?
在 Python 2.7 中,'f' 格式四舍五入到最接近的
>>> "{:.0f}".format(2.85)
'3'
>>> "%.0f"%2.85
'3'
>>> "%.1f"%2.85
'2.9'
>>> "%i"%2.85
'2'
Run Code Online (Sandbox Code Playgroud)