-1

I have a randomly generated float from the random library, and I want to shorten it to any number of places, based on some other number.

Example:

input = 4.06098152

processing the number, rounding to thousandths place

output = 4.061

How would I do this?

1 Answers1

2

You can use the built in round function: The second argument in the paranthesis gives the amount of digits to round off

x=input("Enter a decimal number: ")
print(round(float(x),3))