Skip to content

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'

@astanin astanin added the incomplete This PR requires some further changes or modifications before it can be merged. label Jul 23, 2025
@mvadari
Copy link
Author

mvadari commented Aug 13, 2025

@astanin three years late but I addressed your comments 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes incomplete This PR requires some further changes or modifications before it can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants