Precise definition of float string formatting?

孤人 提交于 2019-12-05 19:30:32
Marcin

As @blckknght explains in comments, '{:20}' specifies a string width of 20; to specify float precision you need a decimal point before it: {:.20} or {:.20g}.

As to why the number is formatted as it is, OP said it: "A general convention is that an empty format string ("") produces the same result as if you had called str() on the value." That's what you're getting, space-padded as per the format string (it's empty as to the number format, and the format can accommodate the full str representation).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!