我有一个初始数字,比方说 3700,我想将它除以一个百分比。我有这段代码:
let available = 3700, percent = 10
for (let index = 0; index < 10; index++) {
let use = index == 0 ? (percent / 100) * available : available / ((percent - index) % percent)
console.log(`Index: ${index} | Use > ${use}`)
console.log(`Before reduction > ${available}`)
available -= use
console.log(`After reduction > ${available}\n`)
}
Index: 0 | Use > 370
Before deduction > 3700
After deduction > 3330
Index: 1 | Use > 370
Before deduction > 3330
After deduction > 2960
...
Index: 9 | Use > 370
Before deduction > 370
After deduction > 0
它的工作原理是除以 10%,但是任何其他百分比数字都会显示出意想不到的结果。
有什么帮助吗?
白板的微信
跃然一笑
尚方宝剑之说
相关分类