Function to format numbers with SI notation

In my use case, I would like to format numbers with SI notation and optional unit.
I’m using it for cutting off numbers as short as possible mainly, just like the stars/forks/issues count on GitHub.

image

Number Unit Result
123 - 123
1234 - 1.234 k
1234 B 1.234 kB
1234000 - 1.234 M
2.2345e-12 F 2.2345 pF

Post topic here to see if there is any missing detail, such as i18n.