如何格式化“ 6.5”浮动为“ 06.5000”与领先的零?

发布于 2025-01-22 00:56:36 字数 178 浏览 3 评论 0原文

我想以06.5000的数据格式输出浮点数数组。

Python有没有办法将小数点和小数点的左侧缩小,例如Awk的printf,还是Matlab的fprintf

我在网上发现的大多数Python建议只是控制小数点右侧的信息。

I want to output the float value array to a CSV-File in a data format like 06.5000.

Is there a way in Python to trim the decimal point and to the left of the decimal point, like awk's printf, or matlab's fprintf?

Most of the Python advice I found on the net was only to control information to the right of the decimal point.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韬韬不绝 2025-01-29 00:56:36

这应该有效:

>>> number = 6.5
>>> f'{number:07.4f}'
# '06.5000'

0指示零指数,7是格式化号码字符串的总长度,.4f是四个小数。浮标的地方。

This should work:

>>> number = 6.5
>>> f'{number:07.4f}'
# '06.5000'

The 0 indicates a leading zero, the 7 is the total length of the formatted number string and .4f is the four decimal places of your float.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文