0

I'm making a simple program where it calculates your average salary per year by just asking a couple questions. So when it calculates it I want it so it has commas and gets rid of hanging zeros.

calculation = (hourly_rate * hours) * 52
format = "{:,}".format(calculation)
format_2 = "{:2f}".format(float(calculation))
#Formatting big numbers to include commas
print("{0}, your average salary for the {1} job, is ${2} per year."
.format(name, occupation, format_2))

The math is 13.65 * 32 * 52 = 22,713.6 But my output is: $22713.600000

What I want: $22,713.06

mkrieger1
  • 14,486
  • 4
  • 43
  • 54
Amar Mujak
  • 15
  • 4

3 Answers3

0

Your second variable format is a python special word, try to call it format_1, and this should help you

Sozy
  • 175
  • 9
0

I believe you're missing a period. I've also simplified things a little:

calculation = (float(input(f"How many hours do you work in a typical week? ")) * float(input(f"Your hourly rate is: "))) * 52
print("Your average salary is ${:,.2f}".format(calculation))
Carewen
  • 65
  • 11
0

You can use round function to remove zeros

round(decimal,1) # 1 is number of digits you want to round off

And check this link for the commas - Commas

PCM
  • 2,692
  • 2
  • 7
  • 29