Package: sciform
sciformRepository:https://github.com/jagerber48/sciformDocumentation:https://sciform.readthedocs.io/en/stable/PyPi:https://pypi.org/project/sciform/We would greatly appreciate you taking the time to fill out theUser Experience Surveyto help
improvesciform.Overviewsciformis used to convert python numbers into strings according to
a variety of user-selected scientific formatting options including
decimal, binary, fixed-point, scientific and engineering formats.
Where possible, formatting follows documented standards such as those
published byBIPMorIEC.sciformprovides certain options, such as engineering notation,
well-controlled significant figure rounding, and separator customization
which are not provided by the python built-informat specification mini-language (FSML).InstallationInstall the latest stable version fromPyPiwith:python -m pip install sciformor install the latest development version fromGitHubwith:python -m pip install git+https://github.com/jagerber48/sciform.gitsciformis compatible with Python versions >=3.9.UsageHere we provide a few key usage examples.
For many more details seeUsage.sciformprovides a wide variety of formatting options which can be
controlled when constructingFormatterobjects which are then used
to format numbers into strings according to the selected options.>>> from sciform import Formatter
>>> formatter = Formatter(
...     round_mode="dec_place", ndigits=6, upper_separator=" ", lower_separator=" "
... )
>>> print(formatter(51413.14159265359))
51 413.141 593
>>> formatter = Formatter(round_mode="sig_fig", ndigits=4, exp_mode="engineering")
>>> print(formatter(123456.78))
123.5e+03Users can also format numbers by constructingSciNumobjects and
using string formatting to format theSciNuminstances according
to a custom FSML.>>> from sciform import SciNum
>>> num = SciNum(12345)
>>> print(f"{num:!2f}")
12000
>>> print(f"{num:!2r}")
12e+03In addition to formatting individual numbers,sciformcan be used
to format pairs of numbers as value/uncertainty pairs.
This can be done by passing two numbers into aFormattercall or by
using theSciNumobject.>>> formatter = Formatter(ndigits=2, upper_separator=" ", lower_separator=" ")
>>> print(formatter(123456.654321, 0.00345))
123 456.654 3 ± 0.003 4
>>> formatter = Formatter(ndigits=4, exp_mode="engineering")
>>> print(formatter(123456.654321, 0.00345))
(123.456654321 ± 0.000003450)e+03>>> num = SciNum(123456.654321, 0.00345)
>>> print(f"{num:!2f}")
123456.6543 ± 0.0034
>>> print(f"{num:!2f()}")
123456.6543(34)Note that the above examples demonstrate thatsciformuses“round-to-even”rounding.>>> print(f"{SciNum(865):!2}")
860
>>> print(f"{SciNum(875):!2}")
880SeeFormatting Options,Format Specification Mini-Languagefor more details andExamplesfor
more examples.Project Statussciformadheres tosemantic versioning.
The major version forsciformis still0indicating thatsciformis still in the development stage which means there may be
backwards-incompatible changes to the interface (e.g. function or object
behaviors and names) without a corresponding major version bump.
All changes are announced after new releases in thechangelog.
Backwards incompatible changes are indicated with the[BREAKING]flag.We are very excited to get your feedback to help stabilize the interface
and makesciforma more useful tool.
You can provide your feedback on your experience withsciformby
filling outthe user experience survey.
Now is a great time to share yoursciformideas or issues by
opening adiscussionorissue.
If you would like to contribute tosciformthen please seeHow to Contribute.sciformhas undergonepeer reviewby thePyOpenScicommunity and been
accepted into the PyOpenSci ecosystem.
You can view the reviewhere.Acknowledgementssciformwas heavily motivated by the prefix formatting provided in
theprefixedpackage and the value ± uncertainty formatting in theuncertaintiespackage.