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

fix decimal precision issue #176

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

mvadari
Copy link

@mvadari mvadari commented Apr 14, 2022

I was having issues where a Decimal object was being outputted incorrectly in the table - the value was 99999998999.999980 and tabulate was called with floatfmt=",.6f", and the output in that cell was 99,999,998,999.999985. This PR fixes that problem.

@mvadari mvadari marked this pull request as draft April 14, 2022 19:01
@mvadari mvadari marked this pull request as ready for review April 14, 2022 21:13
@astanin
Copy link
Owner

astanin commented Jun 22, 2022

I suppose that tabulate should not convert all float values to Decimal, but rather stick to the basic float type instead.
However, if the user passes Decimal explicitly, it should printed as you suggest.

So the tests should be something like this:

>>> tabulate([[float("0.123456789012345678901")]], tablefmt='plain', floatfmt=".21f")
'0.123456789012345677370'
>>> tabulate([[Decimal("0.12345678901234567891")]], tablefmt='plain', floatfmt=".21f")
'0.123456789012345678901'

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

Successfully merging this pull request may close these issues.

2 participants