工资计算器的小demo

来源:互联网 发布:java手机下载 编辑:程序博客网 时间:2024/05/17 08:21

不知道大家每个月发工资了会不会自己亲手再计算一遍,特别是工资不固定的朋友.所以我写了一个安卓的小demo,可以帮助大家计算工资,方便又快捷.

目前我是根据我公司的发放标准来计算的,大部分应该是这样的,如果哪有区别可以提建议,我尽量把它做的大众化.我们公司免缴税额是3500,缺勤和加班每天的工资是基本工资/21.75,纳税的方式是按照北京纳税标准来的.现在最高纳税工资是35000元,再高了就计算不了了.

计算的方式是按照含税级距的范围*税率计算的.有个速算扣除数,我到现在还没有弄明白是啥意思,在网上可以查了一些关于这方面的东西,但我计算时好像跟他没有关系,别人用了也没有错误.本软件现在还有什么高的技能点,就有一个四舍五入保留两位小数.不过我会一直维护的,因为我也在用,如果大家想用可以到我的github上下载对应的demo.

我把我的代码贴出来吧!欢迎赐教.

public class MainActivity extends AppCompatActivity {EditText et_basic;//基本工资EditText et_insure;//五险一金EditText et_absence;//缺勤EditText et_overtime;//加班TextView tv_allRate;//总的个人所得税TextView tv_finalSalary;//最后所得工资@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);et_basic = (EditText) findViewById(R.id.et_basic);et_insure = (EditText) findViewById(R.id.et_insure);et_absence = (EditText) findViewById(R.id.et_absence);et_overtime = (EditText) findViewById(R.id.et_overtime);tv_allRate = (TextView) findViewById(R.id.tv_allRate);tv_finalSalary = (TextView) findViewById(R.id.tv_finalSalary);}public void calculator(View view) {String basic = et_basic.getText().toString().trim();String insure = et_insure.getText().toString().trim();String absence = et_absence.getText().toString().trim();String overtime = et_overtime.getText().toString().trim();float basicSalary = Float.parseFloat(basic);float insureGold = Float.parseFloat(insure);int absenceDay = Integer.parseInt(absence);//获取缺勤天数int overtimeDay = Integer.parseInt(overtime);//获取加班天数//计算应得工资//如果加班或缺勤,每天的工资为double perDay = basicSalary / 21.75;//计算总工资 = 基本工资 + 加班的工资 - 缺勤的工资double allSalary = basicSalary + overtimeDay * perDay - absenceDay * perDay;double youHave = allSalary - insureGold;if (youHave < 0) {ToastUtils.show("吃饭的钱都没有了,还上五险作甚!");return;}//需要纳税的工资 = 总工资 - 五险一金 - 免征额(3500)double payRate = youHave - 3500;//由于是个人纳税,所以使用含税级距的标准double allRate = 0;if (payRate > 0) {allRate = caculateRate(payRate);}//最后赢得工资为double finalSalary = youHave - allRate;//给控件赋值tv_allRate.setText(roundDouble(allRate) + "");tv_finalSalary.setText(roundDouble(finalSalary) + "");}/** * 传入工资纳税的部分,获取总共需要交纳的个人所得税 * @param payRate 传入工资纳税的部分 * @return 总共需要交纳的个人所得税 */private double caculateRate(double payRate) {double allRate = 0;/** * 标准:      含税级距    税率(%) *          不超过1500       3 *          1500-4500       10 *          4500-9000       20 *          9000-35000      25 */if (payRate < 1500) {allRate = payRate * 0.03;} else if (payRate < 4500) {allRate = 45 + (payRate - 1500) * 0.1;} else if (payRate < 9000) {allRate = 45 + 300 + (payRate - 4500) * 0.2;} else if (payRate < 35000) {allRate = 45 + 300 + 900 + (payRate - 9000) * 0.1;}return allRate;}/** * 小数 四舍五入 保留2位 * * @param val 原始小数 * @return 四舍五入后保留的小数 */public static Double roundDouble(double val) {Double ret = null;try {double factor = Math.pow(10, 2);ret = Math.floor(val * factor + 0.5) / factor;} catch (Exception e) {e.printStackTrace();}return ret;}}


1 0
原创粉丝点击