java - 以小数位报告金额
问题描述
我正在制定一个所得税计划,其中的计算是基于 - 申请状态和 - 应税收入
所有部分必须在小数点后正好有两位数。
问题是输出在小数位后显示两个零,而不是预期的数字。
例如:
预期价值> 单次申请:42806 美元。5 0
实际价值> 单次申报:42806 美元。0 0
到目前为止,这是我的代码:
// Single Status
if (status == 1) {
if (income > 0 && income <= 8350) {
double firstTax = (int)(income * (0.10));
double totalTax = firstTax;
result = "Single Filing: $" + String.format("%.2f",totalTax) + "(Part I: $" + String.format(("%.2f"),firstTax) + ")";
}
else if (income >= 8350 && income <= 33950) {
double firstTax = (int)(8350 * (0.10));
double secondTax = (int)( (income - 8350) * (0.15));
double totalTax = firstTax + secondTax;
result = "Single Filing: $" + String.format("%.2f",totalTax) + "(Part I: $" + String.format(("%.2f"),firstTax) + ", Part II: $" + String.format(("%.2f"),secondTax) + ")";
}
else if (income >= 33950) {
double firstTax = (int)(8350 * (0.10));
double secondTax = (int)( (33950 - 8350) * (0.15));
double thirdTax = (int)((income - 33950) * (0.25));
double totalTax = firstTax + secondTax + thirdTax;
result = "Single Filing: $" + String.format("%.2f",totalTax) + "(Part I: $" + String.format(("%.2f"),firstTax) + ", Part II: $" + String.format(("%.2f"),secondTax) + ", Part III: $" + String.format(("%.2f"),thirdTax) + ")";
}
}
解决方案
您正在将它们投射到int
. 这将摆脱任何小数。删除(int)
它,它应该有正确的小数。
推荐阅读
- wpf - 如何通过 Behavior 和 VisualStateManager 将 TextBox 设置为特定的内置 VisualState
- kubernetes - 错误:未提供配置,尝试设置 KUBERNETES_MASTER 环境变量
- mysql - Error_code: 2005 - Mysql Operator - 连接到主服务器时出错
- php - 是否可以将标签 URL 与类别 URL 结合起来?
- r - dplyr:在 mutate_at 函数中访问列名
- dynamics-crm - 如何在功能区工作台上为 HomePageGrid 传递 executionContext
- python - 如何去除 Q-Chart 背景颜色并使其透明
- python - 将装饰和包装的功能导入烧瓶中的蓝图
- mysql - 以设定的时间间隔从 MySql 中删除/修改数据
- python - 动态创建的按钮不会触发功能