<i id='1xMfj'><tr id='1xMfj'><dt id='1xMfj'><q id='1xMfj'><span id='1xMfj'><b id='1xMfj'><form id='1xMfj'><ins id='1xMfj'></ins><ul id='1xMfj'></ul><sub id='1xMfj'></sub></form><legend id='1xMfj'></legend><bdo id='1xMfj'><pre id='1xMfj'><center id='1xMfj'></center></pre></bdo></b><th id='1xMfj'></th></span></q></dt></tr></i><div id='1xMfj'><tfoot id='1xMfj'></tfoot><dl id='1xMfj'><fieldset id='1xMfj'></fieldset></dl></div>

  • <legend id='1xMfj'><style id='1xMfj'><dir id='1xMfj'><q id='1xMfj'></q></dir></style></legend>

    <small id='1xMfj'></small><noframes id='1xMfj'>

        <tfoot id='1xMfj'></tfoot>
          <bdo id='1xMfj'></bdo><ul id='1xMfj'></ul>
      1. 将“十进制标记"千位分隔符添加到数字

        时间:2023-06-06
        <i id='pqV9Q'><tr id='pqV9Q'><dt id='pqV9Q'><q id='pqV9Q'><span id='pqV9Q'><b id='pqV9Q'><form id='pqV9Q'><ins id='pqV9Q'></ins><ul id='pqV9Q'></ul><sub id='pqV9Q'></sub></form><legend id='pqV9Q'></legend><bdo id='pqV9Q'><pre id='pqV9Q'><center id='pqV9Q'></center></pre></bdo></b><th id='pqV9Q'></th></span></q></dt></tr></i><div id='pqV9Q'><tfoot id='pqV9Q'></tfoot><dl id='pqV9Q'><fieldset id='pqV9Q'></fieldset></dl></div>
      2. <small id='pqV9Q'></small><noframes id='pqV9Q'>

        • <bdo id='pqV9Q'></bdo><ul id='pqV9Q'></ul>
            <legend id='pqV9Q'><style id='pqV9Q'><dir id='pqV9Q'><q id='pqV9Q'></q></dir></style></legend>

              <tbody id='pqV9Q'></tbody>
            <tfoot id='pqV9Q'></tfoot>

                  本文介绍了将“十进制标记"千位分隔符添加到数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在 Python 中将 1000000 格式化为 1.000.000?'.' 在哪里是小数点千位分隔符.

                  How do I format 1000000 to 1.000.000 in Python? where the '.' is the decimal-mark thousands separator.

                  推荐答案

                  如果要添加千位分隔符,可以这样写:

                  If you want to add a thousands separator, you can write:

                  >>> '{0:,}'.format(1000000)
                  '1,000,000'
                  

                  但它只适用于 Python 2.7 及更高版本.

                  But it only works in Python 2.7 and above.

                  请参阅格式字符串语法.

                  在旧版本中,您可以使用 locale.format():

                  In older versions, you can use locale.format():

                  >>> import locale
                  >>> locale.setlocale(locale.LC_ALL, '')
                  'en_AU.utf8'
                  >>> locale.format('%d', 1000000, 1)
                  '1,000,000'
                  

                  使用 locale.format() 的额外好处是它将使用您的语言环境的千位分隔符,例如

                  the added benefit of using locale.format() is that it will use your locale's thousands separator, e.g.

                  >>> import locale
                  >>> locale.setlocale(locale.LC_ALL, 'de_DE.utf-8')
                  'de_DE.utf-8'
                  >>> locale.format('%d', 1000000, 1)
                  '1.000.000'
                  

                  这篇关于将“十进制标记"千位分隔符添加到数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python TypeError:格式字符串的参数不足 下一篇:如何格式化列表以在 python 的单独行上打印每个元素?

                  相关文章

                  • <bdo id='VNcoi'></bdo><ul id='VNcoi'></ul>
                    <legend id='VNcoi'><style id='VNcoi'><dir id='VNcoi'><q id='VNcoi'></q></dir></style></legend>
                    <i id='VNcoi'><tr id='VNcoi'><dt id='VNcoi'><q id='VNcoi'><span id='VNcoi'><b id='VNcoi'><form id='VNcoi'><ins id='VNcoi'></ins><ul id='VNcoi'></ul><sub id='VNcoi'></sub></form><legend id='VNcoi'></legend><bdo id='VNcoi'><pre id='VNcoi'><center id='VNcoi'></center></pre></bdo></b><th id='VNcoi'></th></span></q></dt></tr></i><div id='VNcoi'><tfoot id='VNcoi'></tfoot><dl id='VNcoi'><fieldset id='VNcoi'></fieldset></dl></div>

                  1. <tfoot id='VNcoi'></tfoot>

                    1. <small id='VNcoi'></small><noframes id='VNcoi'>