用JavaScript实现原币不含税金额、税额可改上下5分钱,超出后提示:不含税金额、税额调整请在原金额的5分钱以内
时间: 2024-05-27 20:11:37 浏览: 29
人民币小写金额转大写金额(java版)
5星 · 资源好评率100%
var originalAmount = 100; // 原币不含税金额
var taxAmount = 10; // 税额
var maxAdjustment = 0.05; // 最大调整金额
function adjustAmounts(originalAmount, taxAmount, adjustment) {
var newOriginalAmount = originalAmount + adjustment;
var newTaxAmount = taxAmount - adjustment;
if (Math.abs(adjustment) > maxAdjustment) {
console.log('不含税金额、税额调整请在原金额的5分钱以内');
return { originalAmount: originalAmount, taxAmount: taxAmount };
} else {
return { originalAmount: newOriginalAmount, taxAmount: newTaxAmount };
}
}
// 调整不含税金额和税额
var newAmounts = adjustAmounts(originalAmount, taxAmount, 0.03);
console.log(newAmounts.originalAmount); // 输出 100.03
console.log(newAmounts.taxAmount); // 输出 9.97
// 调整超出最大调整金额
var newAmounts2 = adjustAmounts(originalAmount, taxAmount, 0.1);
console.log(newAmounts2.originalAmount); // 输出 100
console.log(newAmounts2.taxAmount); // 输出 10
阅读全文