I'm trying to use an input function in python and want to format how the input actually displays in python.
The code is currently:
price = float(input("Enter value: "))
and prints out the following if I input 9.0:
Enter value: 9.0
How do I format the output so that it only shows the value with 0 decimal points i.e., should print out
Enter value: 9
CodePudding user response:
You can modify your code as:
price = float(input("Enter value: "))
price = int(price)
print(price)
This will convert float into an integer.
CodePudding user response:
You can convert float to int like this and the round function will round off the number:
price = float(input("Enter value: "))
price = int(price)
print(round(price))
CodePudding user response:
price = int(float(input("Enter value: ")))
