-
Notifications
You must be signed in to change notification settings - Fork 87
Prevent numbers from being formatted in scientific notation in forms #3208
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom decimal field values in the view mode are getting scientifically notated.
20f5930
to
537c391
Compare
Fixed in (rebased) commit 537c391. I also fixed formatting for numbers in the edits sidebar, and made sure we don't show trailing zeros |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest updates get rid of scientific notation everywhere, but we have some trailing periods to deal with.
opentreemap/treemap/util.py
Outdated
def num_format(num): | ||
if isinstance(num, float): | ||
# Allow for up to 10 digits of precision, but strip trailing 0s | ||
return '{0:.10f}'.format(num).rstrip('0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7bdee5f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need one more tweak to the zero handing.
opentreemap/treemap/util.py
Outdated
def num_format(num): | ||
if isinstance(num, float): | ||
# Allow for up to 10 digits of precision, but strip trailing '0' or '.' | ||
return '{0:.10f}'.format(num).rstrip('0.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this rstrip
call will remove too many characters when the whole number portion of the decimal ends in 0.
In [1]: '120.0'.rstrip('0.')
Out[1]: '12'
Chaining rstrip
s looks like it will give us what we are looking for
In [2]: '120.0'.rstrip('0').rstrip('.')
Out[2]: '120'
In [3]: '120.01'.rstrip('0').rstrip('.')
Out[3]: '120.01'
In [4]: '120.010'.rstrip('0').rstrip('.')
Out[4]: '120.01'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh... sorry for all the back and forth. Fixed in 149dfea
7bdee5f
to
149dfea
Compare
Connects to #2733