<div dir="ltr"><div><div>Hi David,<br><br></div>Perhaps the "n" locale-dependent number formatting specifier<br></div><div>should accept a , to have locale-appropriate formatting of thousand separators?<br><br><font face="monospace, monospace">f"{x:,n}"<br><br></font></div><div><font face="monospace, monospace">would Do The Right Thing(TM) depending on the locale.<br></font></div><div><br></div><div>Today it is an error.<br></div><div><br></div>Stephan<br><div class="gmail_extra"><br><div class="gmail_quote">2018-01-28 7:25 GMT+01:00 David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In South Asia, a different style of digit delimiters for large numbers is used than in Europe, North America, Australia, etc. With some minor spelling differences, the term lakh is used for a hundred-thousand, and it is generally written as '1,00,000'.<div><br></div><div>In turn, a crore is 100 lakh, and is written as '1,00,00,000'. Extending this pattern, larger numbers continue to use two digits in groups (other than the smallest grouping of three digits. So, e.g. 1e12 is written as 10,00,00,00,00,000.<br clear="all"><div><br></div><div>It's nice that we now have the optional underscore in numeric literals. So we could write a number as either `12_34_56_78_00_000` or `1_234_567_800_000` depending on what region of the world and which convention was more familiar.</div><div><br></div><div>However, in *formatting* those numbers, the format mini-language only allows the European convention. So e.g.</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><font face="monospace, monospace">In [1]: x = 12_34_56_78_00_000</font></div></div></div><div><div><div><font face="monospace, monospace">In [2]: "{:,d}".format(x)</font></div></div></div><div><div><div><font face="monospace, monospace">Out[2]: '1,234,567,800,000'</font></div></div></div><div><div><div><font face="monospace, monospace">In [3]: f"{x:,d}"</font></div></div></div><div><div><div><font face="monospace, monospace">Out[3]: '1,234,567,800,000'</font></div></div></div></blockquote><div><div><br></div><div>In order to get Indian number delimiters, you'd have to write a custom formatting function, notwithstanding that something like 1.5 billion people use the three-then-two delimiting convention.</div><div><br></div><div>I propose that Python should have an additional grouping option, or some other way to specify this grouping convention. Oddly, the '_' grouping symbol is available, even though no one actually uses that grouper outside of programming languages like Python, e.g.:</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><font face="monospace, monospace">In [4]: f"{x:_d}"</font></div></div></div><div><div><div><font face="monospace, monospace">Out[4]: '1_234_567_800_000'</font></div></div></div></blockquote><div><div><br></div><div>I guess this is nice for something like round-tripping numbers used in code, but it's not a symbol anyone uses "natively" (I understand why comma or period cannot be used in numeric literals since they mean something else in Python already).</div><div><br></div><div>I'm not sure what symbol or combination I would recommend, but finding something suitable shouldn't be so hard. Perhaps now that backtick no longer has any other meaning in Python, it could be used since it looks similar to a comma. E.g. in Python 3.8 we might have:</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace">>>> f"{x:`d}"<br>'12,34,56,78,00,000'</font><br><br></blockquote>(actually, this probably isn't any parser issue even in Python 2 since it's already inside quotes; but the issue is moot).<div><br></div><div>Or maybe a two character version like:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">>>> f"{x:2,d}"</font></div><div><span style="font-family:monospace,monospace">'12,34,56,78,00,000'</span><br></div></blockquote><div><div><br></div><div>Or: </div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">>>> f"{x:,,d}"</font></div><div><span style="font-family:monospace,monospace">'12,34,56,78,00,000'</span><br></div></blockquote><div></div></div><div><br></div><div>Even if `2,` was used, that wouldn't preclude giving an additional length descriptor after it. Now we can have:</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace">>>> f"{x:,.2f}"</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace">'1,234,567,800,000.00'</font><br><br></blockquote>Perhaps in the future this would work:<div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">>>> f"{x:2,.2f}"</font></div><div><span style="font-family:monospace,monospace">'12,34,56,78,00,000.00'</span><br></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><br></blockquote><span class="HOEnZb"><font color="#888888"><div><div>-- <br><div class="m_-5325080732933759714gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div></font></span></div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br></div></div>