【问题标题】:Python's tabulate number of decimal [closed]Python制表小数位数[关闭]
【发布时间】:2017-01-24 19:00:57
【问题描述】:

有没有办法为 Python 模块tabulate 定义格式样式(小数位数)?

例如:

我有号码3.34643745

我想将小数位数格式化为只打印两位小数。

输出:3.34

【问题讨论】:

标签: python format


【解决方案1】:

是的,你可以这样做:

print tabulate([["pi",3.141593],["e",2.718282]], floatfmt=".2f")

将打印的内容:

--  ----
pi  3.14
e   2.71
--  ----

Here is a link to the documentation.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2015-03-10
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多