-
Notifications
You must be signed in to change notification settings - Fork 72
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
Zero values with certain scales are formatted with E #132
Comments
These formatting issues are rough... So you would expect followed by twelve zeros, right? |
Try setting this environment variable at build time.
|
Yes, that would be what I'd expect. And setting that environment variable does result in the correct value it looks like. |
Yeah, zero is a special case that needs to be dealt with here. Here's the formatting given
I consider this a bug that zero formats in exponential format given a requested precision. I don't have time to work on it for a few weeks. But I'm glad there's an escape hatch in the meantime. When 0.4.6 is out you can drop the environment variable. |
Note to myself: a zero value with |
To those interested: we have to handle formatting numbers with leading zeros (between decimal place and first nonzero digit) specially, because a value of As a default I used max 5 leading zeros before switching to exponential, following Python's example >>> from decimal import Decimal
>>> for exp in range(11): print(Decimal(f"1e{-exp}"))
...
1
0.1
0.01
0.001
0.0001
0.00001
0.000001
1E-7
1E-8
1E-9
1E-10 There's no special case for zero, so any zero with a scale (ex "0.000000" or "0e-6") will trigger the code to deal with "too many leading-zeros". The threshold is configurable with that environment variable, so you could bump up to whatever value you want if you're sure you're always requesting 12 digits of precision, or you aren't dealing with potentially malicious users/numbers. |
I'm not sure if I'm just doing something horribly wrong or if this is a bug, but consider the following program:
This currently generates as output:
It only happens once the scale is large enough. I am parsing numbers passed via an API that are guaranteed to have 12 decimal places, so that's how it came up.
The text was updated successfully, but these errors were encountered: