作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个简单的图表,如输出。这是我要显示的字符串:
a = "名称", b = "10000.00", c = "代码", d = "45.60", e = "30.00"
print("{0:20}${1:,20}{2:20}${3:,20}${4:,<5}".format(a,b,c,d,e),file=outfile)
print("{0:20}${1:,20}{2:20}${3:20}${4:<5}".format(a,b,c,d,e),file=outfile)
ValueError: Invalid format specifier
最佳答案
根据 docs , 宽度必须在逗号之后。此外,您的 b
变量必须是一个数字(而不是一个字符串,就像在你的 MWE 中一样):
>>> x = 10000.0
>>> '{0:20,}'.format(x)
' 10,000.0'
关于python - 千位格式说明符无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39934706/
我正在使用报表查看器控件 (rdlc) 生成报表。我的一列表示来自 SQL 数据库的十进制值,例如: 5199.9800 在此列的末尾,汇总了所有金额。因此,金额行以这种方式表示: =Fields!
我在这段代码中尝试用以下模式替换引号 (') 的千位分隔符 (.):###'###,## import java.text.*; public class NumberFormatTests
对于具有财务计算的网站,我尝试将包含在 HTML 输入字段中的每个数字转换为 xxx,xxx,xxx.xx 格式,其中千位分隔符为逗号,小数点为小数点。与我们从 Excel 中了解到的类似。 现在是挑
有没有一种方法可以使用字符串格式化程序将 Thousands、Millions、Billions 格式化为 123K、123M、123B 而无需更改代码以将值除以 Thousand、Million 或
我是一名优秀的程序员,十分优秀!