nrc-cnrc / MetroloPy

Tools for uncertainty propagation and measurement unit conversion — Outils pour la propagation des incertitudes et la conversion d'unités de mesure
https://nrc-cnrc.github.io/MetroloPy
GNU General Public License v3.0
34 stars 6 forks source link

thousand_spaces #26

Open userJay opened 3 years ago

userJay commented 3 years ago

As far as I know standard conform spacing is: 4.899 7 kΩ ± 1.1 Ω 4.899 68 kΩ ± 0.1 Ω 4.899 681 kΩ ± 0.01 Ω

Currently it is in the first case like this: 4.8997 kΩ ± 1.1 Ω

so the first should be: "nr < 4 and nl < 4: " and "if nr >= 4: " and " if nl >= 4:".

Modul is ummy.py

elif self.thousand_spaces:

if nr < 4 and nl < 4:
    return s + ellipses

s = list(s)
if nr >= 4:
    for i in range(int(nr/3)):
        s.insert(d + i + (i+1)*3 + 1, sp)
if nl >= 4:
    for i in range(int(nl/3)):
        s.insert(d - (i+1)*3, sp)

I love your great work with MetrolPy! I'm sorry, for my bad contribution quality - I'm a rooky in this issue. But I'll soon learn how to to proper issues, push, pulls and what ever exist to contribute good way.

hvparks commented 3 years ago

This is intentional, see for example https://www.bipm.org/en/publications/si-brochure section 5.4.4:

"However, when there are only four digits before or after the decimal marker, it is customary not to use a space to isolate a single digit. The practice of grouping digits in this way is a matter of choice..."

However that does bring up the question of what happens when one more decimal place is added, should it be 4.899 6814 or 4.899 681 4? The SI Brochure seems to follow the former, but MetroloPy displays it as the latter at the moment.

I really appreciate your comments

userJay commented 3 years ago

Okay - also a interesting source. I'm following ISO 80000-1 section 7.3.1. The example is: 1 234,567 8 in stead of 1234,4578.

ftessier commented 3 years ago

For the purpose of parsing the output, it might prove useful to add an option to output without typographical separators (if not already the case), or to use _ as the thousands separator instead of spaces. Notably, python, julia and rust all allow '_' in numbers for this purpose, which is great to clarify long numbers in the code!

hvparks commented 3 years ago

setting "uc.gummy.thousand_spaces = False" does turn off the separators, though there is currently no option to change the separators. The separators are spaces in unicode output and thin spaces in html and latex output.

ftessier commented 3 years ago

Kudos for the thin space output in html and latex!! 🏅