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

Support decimal place rounding for value/uncertainty pairs. #170

Open
jagerber48 opened this issue Mar 8, 2024 · 1 comment · May be fixed by #171
Open

Support decimal place rounding for value/uncertainty pairs. #170

jagerber48 opened this issue Mar 8, 2024 · 1 comment · May be fixed by #171

Comments

@jagerber48
Copy link
Owner

Currently if users are interested in well-controlling the position of the decimal separator within a string they can do so using round_mode="dec_place" and left_pad_dec_place. E.g.

from sciform import Formatter

formatter = Formatter(
    round_mode="dec_place",
    ndigits=5,
    left_pad_char=0,
    left_pad_dec_place=4,
)

for number in (123, 3453.39485345, 39.532, 9, 42, 8923.9823423):
    print(formatter(number))

# 00123.00000
# 03453.39485
# 00039.53200
# 00009.00000
# 00042.00000
# 08923.98234

Because dec_place rounding is not supported for value/uncertainty formatting this same strategy is not possible.

@jagerber48
Copy link
Owner Author

I've leaned away from including this feature because I think dec_place rounding is a bad practice for value/uncertainty formatting. The official recommendations indicate that value/uncertainty pairs should be formatted according to significant digits of the uncertainty. However, it seems there is anyways demand to "line up" decimal symbols by controlling the digits to the right of the decimal symbol with dec_place and ndigits and the decimal to the left of the decimal symbol with left_pad_dec_place.

I will include this feature along with a recipe for how to line up decimal symbols in the examples. But I'll include in the documentation caution against using round_mode="dec_place" and explanation for the caution. The main issues are (1) if too few digits of uncertainty are shown then the uncertainty may be rendered as something like 0.0000 and (2) too many digits of uncertainty may be shown such as 1.23456789 when really only the first one or two are typically known or needed.

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

Successfully merging a pull request may close this issue.

1 participant