首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >转换为货币并打印BiWeekly计划

转换为货币并打印BiWeekly计划
EN

Stack Overflow用户
提问于 2017-06-20 21:56:37
回答 1查看 602关注 0票数 0

我刚开始接触Python,至少可以说我是个新手。我正在使用PyCharm,并且正在尝试组合一些用于输入员工数据的基本内容。

我相信您可以看到我的脚本中的要点。不管怎么说,首先我试了一下,把工资、奖金和年薪都写成货币,但是不能,你知道是60,000美元,而不是60000美元。

此外,我希望它给出一个双周支付时间表,如果你输入了第一个工资支票的日期。

我在试着头脑风暴。

代码语言:javascript
复制
name = input('Enter Employee Name: ')
# This should be an integer that represents the age of an employee at GPC
try:
    age = int(input('Enter Employee Age: '))
except:
    print('Please enter a whole number')
    exit()
job = input('Enter Employee Job: ')
# This should be an integer that represents the salary of the employee at 
GPC
try:
    salary = int(input('Enter Employee Salary to the Nearest Dollar: '))
except:
    print('Please enter only numbers without foreign characters')
    exit()
salary_bonus = int(input('Enter employee bonus percentage '))/100
annual_income = (salary * salary_bonus) + salary
import datetime
now = datetime.datetime.now() # Current Year
u = datetime.datetime.strptime('2016-12-30','%Y-%m-%d')
d = datetime.timedelta(weeks=2)
t = u + d

# Data Output

print('Employee: ', name)
print('Age: ', age)
print('Job Title: ', job)
print('Annual Salary: ', round(salary,2))
print('Biweekly Paycheck: ', round(salary / 26, 2))
print('Bonus for', now.year, ': ', round(salary * salary_bonus, 2))
print('Actual Annual Income: ', round(annual_income, 2))

print('Your pay schedule will be:')
print(t)
print(t+d)
EN

回答 1

Stack Overflow用户

发布于 2017-06-20 22:15:20

您可以使用local.currency

代码语言:javascript
复制
import locale
locale.setlocale( locale.LC_ALL, '' )
print('Actual Annual Income: ', locale.currency(round(annual_income, 2), grouping=True))

locale.currency(val,symbol=True,grouping=False,international=False)

根据当前LC_MONETARY设置格式化数字val。

如果symbol为true,则返回的字符串包括货币符号。如果grouping为true (这不是默认值),则使用该值进行分组。如果international为true (这不是默认值),则使用国际货币符号。

请注意,此函数不适用于‘C’语言环境,因此您必须首先通过setlocale()设置语言环境。

参考:Python Documents: Internationalization services

附注:有关每两周支付一次的时间表,请参阅Generating recurring dates using python?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44655125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档