Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: for numbers, apply the “digit grouping” for integers and floats. #320

Open
airvzxf opened this issue Apr 14, 2024 · 0 comments

Comments

@airvzxf
Copy link
Contributor

airvzxf commented Apr 14, 2024

Feature: for numbers, apply the “digit grouping” for integers and floats.

Context

Decimal separator

A decimal separator is a symbol used to separate the integer part from the fractional part of a number written in decimal form (e.g., “.” in 12.45).

https://en.wikipedia.org/wiki/Decimal_separator

Digit grouping

In general, digits should be grouped and separated either by commas or by narrow gaps (never a period/full point).

https://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Dates_and_numbers#Grouping_of_digits

Python

format(value, format_spec='')

Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument; however, there is a standard formatting syntax that is used by most built-in types: Format Specification Mini-Language.

https://docs.python.org/3.11/library/functions.html#format

Format Specification Mini-Language

“Format specifications” are used within replacement fields contained within a format string to define how individual values are presented.

grouping_option ::= "_" | ","

https://docs.python.org/3.11/library/string.html#formatspec

Description

Currently, “tabulate” makes a distinction between integers and floats. However, the “intfmt” parameter applies the “digit grouping” format exclusively to integers, excluding floats. This prevents a decimal containing more than 3 numbers from being grouped. For example, the number “1234567.89” should be displayed in this format: “1,234,567.89”.

Suggestion

Implement functionality to perform “digit grouping”, regardless of whether the column type is a float or integer. This includes changing the “intfmt” parameter to “digitgrp” or something similar. In the source code, if it is an integer or float number, the format assigned in the “digitgrp” parameter would be applied to it.

Conflicts

Applying this feature will be in conflict with the issue #318. I suggest to first finishing and merging the solutions related to this issue, then working on this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant