第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

將一個(gè)數(shù)除以百分比

將一個(gè)數(shù)除以百分比

呼喚遠(yuǎn)方 2023-06-15 17:18:41
我有一個(gè)初始數(shù)字,比方說 3700,我想將它除以一個(gè)百分比。我有這段代碼:let available = 3700, percent = 10for (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 > 370Before deduction > 3700After deduction > 3330 Index: 1 | Use > 370   Before deduction > 3330After deduction > 2960 ...Index: 9 | Use > 370Before deduction > 370After deduction > 0它的工作原理是除以 10%,但是任何其他百分比數(shù)字都會(huì)顯示出意想不到的結(jié)果。有什么幫助嗎?
查看完整描述

3 回答

?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊

重要變化:修改了三元運(yùn)算并更改了循環(huán)測(cè)試


請(qǐng)參閱下面的工作代碼:


let available = 3700, percent = 20


for (let index = 0; index < 100/percent; index++) {

    let use = index == 0 ? (percent / 100) * available : available / (100/percent - index)


    console.log(`Index: ${index} | Use > ${use}`)


    console.log(`Before reduction > ${available}`)

    available -= use

    console.log(`After reduction > ${available}\n`)

}


查看完整回答
反對(duì) 回復(fù) 2023-06-15
?
躍然一笑

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊

在定義使用時(shí)去掉條件。這應(yīng)該解決它。


let available = 3700, percent = 10

let availableBeginning = available


for (let index = 0; available > 0 ; index++) {

    let use = percent / 100) * availableBeginning


     console.log(`Index: ${index} | Use > ${use}`)


     console.log(`Before reduction > ${available}`)

     available -= use

     console.log(`After reduction > ${available}\n`)

}


查看完整回答
反對(duì) 回復(fù) 2023-06-15
?
尚方寶劍之說

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊

這將適用于您的情況。我不確定為什么你有 `available / ((percent - index) % percent)),這基本上只是將你的原始數(shù)字除以你想要扣除的百分比,然后取模原始百分比。因此,在這種情況下,在 0 之后,您的行為是 use = 878.75,因?yàn)槟鷮?3515 除以 (5 - 1) % 5,即 = 4. 3515 / 4 = 878.85。這將扣除得相當(dāng)快,因?yàn)槟看蔚辽賹?1 / 百分比值作為已扣除數(shù)字的整數(shù)。


事實(shí)證明,你的使用邏輯實(shí)際上是沒有意義的,如果你想每次迭代都扣除偶數(shù),你不必根據(jù)任何邏輯設(shè)置它......只需重復(fù)計(jì)算和扣除多少次你想要的.


無論如何,這是解決方案:


let available = 3700, percent = 5;

// This is going to be the constant deduction you will continue to use

let deduction = 3700 * (percent / 100);


for (let index = 0; index < 10; index++) {

    console.log(`Index: ${index} | Use > ${deduction}`)


    console.log(`Before deduction > ${available}`)

    available -= deduction

    console.log(`After deduction > ${available}\n`)

}


查看完整回答
反對(duì) 回復(fù) 2023-06-15
  • 3 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)