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

uses scientific notation when not necessary #1

Open
goldmanm opened this issue Sep 25, 2016 · 4 comments
Open

uses scientific notation when not necessary #1

goldmanm opened this issue Sep 25, 2016 · 4 comments

Comments

@goldmanm
Copy link

When inputting to_precision(132,2), I would expect it to return '130', but it actually gives '1.3e+2'. To my knowledge, both have the valid amount of significant figures, and the first one is easier to read. We might want to add a trailing zeros check.

I tried it on python 2.7 and 3.4 and got the same result.

Thanks so much for sharing this. I really like the code.

@randlet
Copy link
Owner

randlet commented Sep 26, 2016

Yes you're right 130 is better there. Maybe for anything less than 1000 (or 10000? 9300 vs 9.3e3) displaying the trailing zeros is better.

@goldmanm
Copy link
Author

The string formatting using the letter 'g' seems to have a default to not use exponential notation if the exponent is between -4 and some number 'p', which I could see also being around 4.

If the significant figures can be used correctly (no significant trailing zeros), checking whether the value of the exponent is between 0 and 4 (or 3), and then displaying that using regular notation might be a way to do this.

@randlet
Copy link
Owner

randlet commented Sep 26, 2016

Yes, I agree following the g formatting makes sense.

@BebeSparkelSparkel
Copy link
Contributor

@goldmanm
I rewrote some of this repo and anything > -1000 and < 1000 will be in standard notation otherwise it goes to scientific notation.

You can check it out at:
github.com/BebeSparkelSparkel/to-precision

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

3 participants