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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!