Two Decimal Places - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Two Decimal Places (/thread-7422.html) |
Two Decimal Places - Fumi - Jan-09-2018 Hi there, I'm just learning python myself. This is probably going to take someone all of two seconds to answer but I cannot find an easy answer to this anywhere. In the following code, how do I print results to display two decimal places? - as in 123.45 #define variables with values fastmail_payment = 2.25 agile_bits = 3.67 text_expander = 3.84 amazon_aws = 16.59 dropbox = 10.46 adobe_creative_cloud = 8.57 icloud_storage = 2.49 feedly = 3.75 google_drive = 15.99 uneasy_nostalgia = 14.40 personal_blog = 8.98 monthly_payments = fastmail_payment + agile_bits + text_expander + amazon_aws + dropbox + adobe_creative_cloud + icloud_storage + feedly + google_drive yearly_payments = monthly_payments * 12 weekly_payments = monthly_payments / 4 daily_payments = monthly_payments / 30 hourly_payments = daily_payments / 24 squarespace_total = uneasy_nostalgia + personal_blog squarespace_total_year = squarespace_total * 12 print "Total for Year is: " , yearly_payments print "Total for Month is: ", monthly_payments print "Total for Week is: ", weekly_payments print "Total for Day is: ", daily_payments print "Total for Hour is: ", hourly_payments print "My Squarespace yearly total payments were: ", squarespace_total_year RE: Two Decimal Places - Windspar - Jan-09-2018 a = 123.456789 print "{0:.2f}".format(a) old way print "%.2f" % a RE: Two Decimal Places - metulburr - Jan-09-2018 Quote:daily_payments = monthly_payments / 30what about months with 31 days? RE: Two Decimal Places - Fumi - Jan-10-2018 (Jan-09-2018, 09:52 PM)metulburr Wrote:Quote:daily_payments = monthly_payments / 30what about months with 31 days? I'm only just beginning Python. I've no idea how to deal with that. (Jan-09-2018, 09:46 PM)Windspar Wrote:a = 123.456789 print "{0:.2f}".format(a) Thanks Windspar! |