This is something I wish was captured in programming more often. The well-loved library academics swear by is https://github.com/SBECK-github/Math-SigFigs but I wish there was a built-in "scientific number" type in every language that could make it easy for everyone to use.