user2950606
user2950606

Reputation: 1

How do I round up to the decimal the second decimal?

I am having difficulty rounding numbers. I have tried including it in my initial descriptions i.e. monthlyInterestrate = round(annualInterestrate/12.0, 2)

and also in several formats when I print, i.e.:

print ('Minimum monthly payment: ' + str(round monthlyPayment),2)

Am I formulating this incorrectly?

Any insight would be greatly appreciated!

Upvotes: 0

Views: 102

Answers (2)

Joran Beasley
Joran Beasley

Reputation: 113998

print "%0.2f"%monthlyPayment 
#or
print "{0:0.2f}".format(3.45678)

should work if your just trying to round it when you print although I should mention it does not always round quite right eg 3.3447 -> 3.34 however 3.345 -> 3.35

Upvotes: 1

Paul Draper
Paul Draper

Reputation: 83283

Doesn't this work?

monthlyPayment = 10.126234
print ('Minimum monthly payment: ' + str(round(monthlyPayment, 2)))

Upvotes: 1

Related Questions