I have this, but it does not work
number = int(input("Please give the number"))
print("Formatted Number: " + "{:.2f}".format(number));
print(number)
I have this, but it does not work
number = int(input("Please give the number"))
print("Formatted Number: " + "{:.2f}".format(number));
print(number)
You are getting error with this code because you are trying to convert the float value to int while taking input. If you want to take a float input from user then round the value as you want and turn it into a string value then you can use the code provided below:
number = float(input("Please give the number")) # take input as float
print("Formatted Number: " + str(round(number,2))) # round upto 2 and convert to string
Please let me know if this is what you are looking for or not.
Following syntax that you mentioned
print("Formatted Number: " + "{:.2f}".format(number));
will work but you cant round int number.
Remove "int" from number = int(input("Please give the number"))
and replace it with "float" number = float(input("Please give the number"))
In place of "int" you can use "eval" more about eval
number = eval(input("Please give the number"))
print("Formatted Number: " + "{:.2f}".format(number));
print(number)