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

0.000123456 shows as '1.23E−40' instead of '1.23E−4' #615

Open
rich-iannone opened this issue Feb 19, 2025 · 1 comment
Open

0.000123456 shows as '1.23E−40' instead of '1.23E−4' #615

rich-iannone opened this issue Feb 19, 2025 · 1 comment

Comments

@rich-iannone
Copy link
Member

Discussed in #614

Originally posted by marceloandrioni February 19, 2025
Sorry if it's a very basic question, but it's my first time using great_tables.

I was trying to better format a very small number using:

from great_tables import vals

vals.fmt_scientific(0.000123456, n_sigfig=3, exp_style="E")
['1.23E−40']

But the exponent keeps showing an extra zero. Does someone can point me to the correct way of doing this?

Thank you.

This issue seems to stem from the use of exp_style= and values not using that arg are unaffected.

@jrycw
Copy link
Collaborator

jrycw commented Feb 23, 2025

if _str_detect(n_part, "-"):
n_part = _str_replace(n_part, "-", "")
n_part = n_part.ljust(n_min_width, "0")
n_part = "-" + n_part
else:
n_part = n_part.ljust(n_min_width, "0")
if force_sign_n:
n_part = "+" + n_part

It looks like the error is caused by the padding 0. Would using str.rjust() instead of str.ljust() help resolve the issue?

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

No branches or pull requests

2 participants