Skip to content

"parts per" form when exponent = 0? #99

@jagerber48

Description

@jagerber48

Discussed in #64

Originally posted by jagerber48 October 17, 2023
Consider

from sciform import Formatter, FormatOptions, ExpMode, ExpFormat
pp_formatter = Formatter(FormatOptions(exp_mode=ExpMode.ENGINEERING,
                                       exp_format=ExpFormat.PARTS_PER,
                                       add_ppth_form=True,
                                       pdg_sig_figs=True))

print(pp_formatter(123e-9, 42e-9))
print(pp_formatter(123e-6, 42e-6))
print(pp_formatter(123e-3, 42e-3))
print(pp_formatter(123e-0, 42e-0))

Which prints

(120 +/- 40) ppb
(120 +/- 40) ppm
(120 +/- 40) ppth
(120 +/- 40)e+00

I'm wondering if, by default, the last output (for when the exponent equals zero) should be

(120 +/- 40)

I lean towards "yes".

This behavior can currently be realized using extra_parts_per_forms={0: ''}.

from sciform import Formatter, FormatOptions, ExpMode, ExpFormat
pp_formatter = Formatter(FormatOptions(exp_mode=ExpMode.ENGINEERING,
                                       exp_format=ExpFormat.PARTS_PER,
                                       add_ppth_form=True,
                                       pdg_sig_figs=True, extra_parts_per_forms={0: ''}))

print(pp_formatter(123e-9, 42e-9))
print(pp_formatter(123e-6, 42e-6))
print(pp_formatter(123e-3, 42e-3))
print(pp_formatter(123e-0, 42e-0))

which gives

(120 +/- 40) ppb
(120 +/- 40) ppm
(120 +/- 40) ppth
(120 +/- 40)
```</div>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions