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

Issue with negative numbers (i.e.<1) in set precision #234

Open
7Tns4 opened this issue Nov 9, 2022 · 0 comments
Open

Issue with negative numbers (i.e.<1) in set precision #234

7Tns4 opened this issue Nov 9, 2022 · 0 comments

Comments

@7Tns4
Copy link

7Tns4 commented Nov 9, 2022

When set the floatprecision digits in the options, for example with
options={'floatprecision': 4}
config.apply_options(options,pdtable)

then the negative numbers are not represented with the given precision, but they are represented in scientific notation.

Looking to the code it seems to be a wanted behavior, i.e.
pandastable\core.py

def setPrecision(self, x, p):
"""Set precision of a float value"""

     if not pd.isnull(x):
         if x<1:
             x = '{:.{}g}'.format(x, p)
         elif self.thousandseparator == ',':
             x = '{:,.{}f}'.format(x, p)
         else:
             x = '{:.{}f}'.format(x, p)
     return x

but could it be modified it as the following (preserving the scientific notation for the numbers between (-1,1))?

def setPrecision(self, x, p):
"""Set precision of a float value"""

    if not pd.isnull(x):
        if x>-1 and x<1:
            x = '{:.{}g}'.format(x, p)
        elif self.thousandseparator == ',':
            x = '{:,.{}f}'.format(x, p)
        else:
            x = '{:.{}f}'.format(x, p)
    return x
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