Skip to content

Instantly share code, notes, and snippets.

@billythedummy
Last active December 30, 2024 09:51
Show Gist options
  • Save billythedummy/2aef3fe565e0e06d9d5f4319b1d7d896 to your computer and use it in GitHub Desktop.
Save billythedummy/2aef3fe565e0e06d9d5f4319b1d7d896 to your computer and use it in GitHub Desktop.
float_to_atomics.py
# float_to_atomics(39.8319163, 9) = '39831916300'
# Does not handle integers e.g. 5000
def float_to_atomics(n, atomics=9):
[w, d] = str(n).split(".")
if len(d) > atomics:
raise f"{n} atomics > {atomics}"
return "".join([w, d.ljust(atomics, '0')])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment