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
  • 19,194
  • 5
  • 54
  • 65
Amar Mujak
  • 15
  • 5

3 Answers3

0

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

Sozy
  • 177
  • 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
  • 143
  • 2
  • 14
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,881
  • 2
  • 8
  • 30