[Python-ideas] Format mini-language for lakh and crore

Nick Coghlan ncoghlan at gmail.com
Thu Feb 1 00:11:42 EST 2018


On 1 February 2018 at 14:11, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 1 February 2018 at 08:14, Eric V. Smith <eric at trueblade.com> wrote:
>> On 1/29/2018 2:13 AM, Nick Coghlan wrote:
>>> Given the example, I think a more useful approach would be to allow an
>>> optional digit grouping specifier after the comma separator, and allow
>>> the separator to be repeated to indicate non-uniform groupings in the
>>> lower order digits.
>>>
>>> If we did that, then David's example could become:
>>>
>>>      >>> print(f"In European format x is {x:,.2f}, in Indian format it
>>> is {x:,2,3.2f}")
>>
>>
>> This just seems too complicated to me, and is overgeneralizing. How many of
>> these different formats would ever really be used? Can you really expect
>> someone to remember what that means by looking at it?
>
> Sure - "," and "_" both mean "digit grouping", the numbers tell you
> how large the groups are from left to right (with the leftmost group
> size repeated as needed), and a single "," means the same thing as
> ",3," for decimal digits, and the same thing as ",4," for binary,
> octal, and hexadecimal digits.

Slight correction here, since the comma-separator is decimal only:

- "," would be short for ",3," with decimal digits
- "_" would be short for "_3_" with decimal digits
- "_" would be short for "_4_" with binary/octal/hexadecimal digits

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list