Skip to content

Instantly share code, notes, and snippets.

@dejurin
Last active Jun 12, 2021
Embed
What would you like to do?
def dcmal(num: float, prec: int = 4) -> str:
if type(num) == float and num < 1:
if str(num).find("e-") >= 0:
e = int(str(num).split("e-")[1])+1
s = "{:.{}f}".format(num, e).replace(',','.').split(".")
else:
s = str(num).replace(',','.').split(".")
last = str(int(s[1]))
return "0." + s[1].replace(last, "") + str(round(float("0." + last), prec)).replace(',','.').split(".")[1]
return '{:g}'.format(round(num, prec))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment