Remove decimal precision not rounding

Viewed 154

I am quite confused with the soultions for removing decimal precision using python.

For instance, I have the following number:

9.1234567891235 --> float.

I want to only 9 digits of number after decimal point. Not rounding.

And the end result also should be float.

I have gone through some solutions. but to hit this directly.

Just guide me to function that I can use.

Thanks

2 Answers

Does this work for you:

num = 9.1234567891235
print(float("%.9f" % num))
# 9.123456789
a= 9.1234567891235

def round_down(a, decimals):
    return round(a - 0.5 * 10**(-decimals), decimals)

round_down(a, decimals=9)
9.123456789
Related