Help with calculating a percent amount

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2006
Posts: 2
Reputation: magnumbi is an unknown quantity at this point 
Solved Threads: 0
magnumbi magnumbi is offline Offline
Newbie Poster

Help with calculating a percent amount

 
0
  #1
Mar 22nd, 2006
Hi everyone, I am new to python and programming in general and I could use some help on converting an integer to a decimal (e.g. 80% to .8). Here is what I have so far but as I'm sure you can tell, it doesn't work:

  1. elif menu_choice == 2:
  2. print 'You chose to calculate Short Term Disability\n'
  3. print 'Enter the annual salary: $'
  4. annual_salary = input('Annual Salary: $')
  5. print 'Enter the coverage percent: '
  6. coverage_percent = input('Coverage Percent: %')
  7. print 'The amount is: $',annual_salary*(coverage_percent/100)
  8. print_menu()
The program calculates coverage amounts for various employee benefits like LTD, STD, Life Insurance. In order to calculate STD I need to convert the percent amount to a decimal. Any ideas on what I can do here?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Help with calculating a percent amount

 
0
  #2
Mar 22nd, 2006
The simplest way would be
coverage_rate = coverage_percent /100.0

Remember an integer division behaves different then a floating-point division in most languages.

80/100 = 0
80/100.0 = 0.8
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 2
Reputation: magnumbi is an unknown quantity at this point 
Solved Threads: 0
magnumbi magnumbi is offline Offline
Newbie Poster

Re: Help with calculating a percent amount

 
0
  #3
Mar 22nd, 2006
Originally Posted by vegaseat
The simplest way would be
coverage_rate = coverage_percent /100.0

Remember an integer division behaves different then a floating-point division in most languages.

80/100 = 0
80/100.0 = 0.8
That worked, thanks for the help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC