Skip to content

cleanup and add "trailing_zeroes" argument to si_format()#8

Open
machineonamission wants to merge 5 commits intocfobel:masterfrom
machineonamission:master
Open

cleanup and add "trailing_zeroes" argument to si_format()#8
machineonamission wants to merge 5 commits intocfobel:masterfrom
machineonamission:master

Conversation

@machineonamission
Copy link

  • some random fixes that pycharm wanted me to do
  • add strip() calls to si_format(). before, if the prefix was nothing there could be a trailing space
  • add trailing_zeroes argument which uses different formatting techniques to include or exclude trailing zeroes (i.e. the 0 in 1.20)

@DrosteEffect
Copy link

"before, if the prefix was nothing there could be a trailing space"

That is the correct behavior. A space is always required between the value and the unit, even if no prefix is used: "The numerical value always precedes the unit and a space is always used to separate the
unit from the number"
.

Source: https://www.bipm.org/documents/20126/41483022/SI-Brochure-9-EN.pdf

For this to be applied consistently, e.g. when directly concatenating the output of si_format() with a unit symbol, the space must be included even when no prefix is used. For example:

"%sV"%si_format(1234)
Out[18]: '1.2 kV'

"%sV"%si_format(123)
Out[19]: '123.0 V'

This is the correct, expected, and consistent behavior.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants