php - 如何将 php number_format() 函数转换为 python

标签 php python

我想将 php 代码转换为 python3。

这是我的 php 代码

echo "<td class='text-left'>".number_format($amount,2)."</td>";

我想把这个 php 转换成 Python。请帮助我

最佳答案

import locale


def number_format(num, places=0):
    return locale.format_string("%.*f", (places, num), True)

使用:

print(number_format(12345.6789, 2))

结果:

12345.68

More info

关于php - 如何将 php number_format() 函数转换为 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56748268/

相关文章:

python - 如何获取一列的不同值的计数

python - 傅里叶级数数据适合 numpy : fft vs coding

php - apc vs eaccelerator vs xcache

php - 选择并计算连接表

python - Django - 关于外键的 AutoField

python - 在将 youtube-dl 用作 python 模块时,如何列出 youtube-dl 中的视频分辨率?

python - 绘制悬停数据和悬停文本

php - Laravel 4.2 自定义分页按钮 - 为每个按钮添加一个 ID 以进行 AJAX 调用

php - MAMP - Phpmyadmin(处理错误,未找到错误代码 : 404, 错误)

c# - 静态字段究竟是如何在内部工作的?