Question: My program involves working with numbers like 1234.56789 and printing them to 2 decimal places like so 1234.56. I've currently been using the .round() function
My program involves working with numbers like 1234.56789 and printing them to 2 decimal places like so 1234.56. I've currently been using the .round() function which works fine in most cases except when there are trailing zeroes. The intended output is 12.00 and the actual output is 12.0. (python 3.7, windows)
My current code is:
new_number =( number * (3/2) - 45)
print('the answer is: {}'.format(round.(new_number, 2))
I've also tried:
new_number =( number * (3/2) - 45)
print('the answer is: {:2f}'.format(round.(new_number, 2))
thanks in advance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
