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

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

小于運(yùn)算符在 PHP 中無法正常工作,而循環(huán)

小于運(yùn)算符在 PHP 中無法正常工作,而循環(huán)

PHP
料青山看我應(yīng)如是 2022-09-17 21:55:36
我正在嘗試根據(jù)每個(gè)積分的金額進(jìn)行一些計(jì)算,以獲得所請(qǐng)求金額中使用的總積分。請(qǐng)參考以下代碼:<?php$amount_perpoints = bcdiv(622.9106666666667,1,2); // AMOUNT OF MONEY PER POINTS$request_amount = 3114.55; //REQUESTED AMOUNT OF POINTS$points = 0; // THIS WILL CONTAIN THE TOTAL POINTS$total_amount = 0; // THIS WILL INCREMENT ACCORDING TO THE PRODUCT OF THE CURRENT POINT AND AMOUNT PER POINTSwhile($total_amount < $request_amount){     $points = $points+0.50; //POINTS INCREMENTING BY 0.5    $total_amount = $points * $amount_perpoints;}echo $points;?>輸出:5.50上面的場景輸出,但我相信它應(yīng)該只是.在迭代的點(diǎn),并且 已經(jīng)具有相同的值。為什么 while 循環(huán)仍然滿足比較變量的兩個(gè)值不小于但等于?5.505.005.00$total_amount$request_amount3114.55
查看完整描述

4 回答

?
一只萌萌小番薯

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

您正在比較浮點(diǎn)數(shù)。嘗試使用

while (bccomp($total_amount, $request_amount) === -1) {


查看完整回答
反對(duì) 回復(fù) 2022-09-17
?
慕神8447489

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

使用小數(shù)分?jǐn)?shù)作為浮點(diǎn)數(shù)進(jìn)行計(jì)算時(shí)會(huì)發(fā)生錯(cuò)誤。浮點(diǎn)數(shù)不能精確表示某些十進(jìn)制數(shù)。僅使用 BC 數(shù)學(xué)函數(shù)進(jìn)行此類計(jì)算。您也不需要循環(huán)。


$amount_perpoints = "622.91"; // AMOUNT OF MONEY PER POINTS

$request_amount = "3114.55"; //REQUESTED AMOUNT OF POINTS for result 5.0

//$request_amount = "3426.005"; //REQUESTED AMOUNT OF POINTS for result 5.5


$point_step = "0.50";


//calculation

$points = bcdiv($request_amount,$point_step,2);

$points = bcdiv($points,$amount_perpoints,0);

$points = bcmul($points,$point_step,1);


//output

var_dump($points);  //string(3) "5.0"


查看完整回答
反對(duì) 回復(fù) 2022-09-17
?
德瑪西亞99

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

<?php

$amount_perpoints = bcdiv(622.9106666666667,1,2); // AMOUNT OF MONEY PER POINTS

$request_amount = 3114.55; //REQUESTED AMOUNT OF POINTS


$points = 0; // THIS WILL CONTAIN THE TOTAL POINTS

$new_points=0;

$total_amount = 0; // THIS WILL INCREMENT ACCORDING TO THE PRODUCT OF THE CURRENT POINT AND AMOUNT PER POINTS


while($total_amount < $request_amount){

    $points=$new_points;

    $new_points = $new_points+0.50; //POINTS INCREMENTING BY 0.5

    $total_amount = $new_points * $amount_perpoints;

}


echo $points;


?>


查看完整回答
反對(duì) 回復(fù) 2022-09-17
?
侃侃無極

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

我認(rèn)為@jeff是對(duì)的:


 $amount_perpoints = bcdiv(622.9106666666667,1,2); // AMOUNT OF MONEY PER POINTS

    $request_amount = 3114.55; //REQUESTED AMOUNT OF POINTS


    $points = 0; // THIS WILL CONTAIN THE TOTAL POINTS

    $total_amount = 0; // THIS WILL INCREMENT ACCORDING TO THE PRODUCT OF THE CURRENT POINT AND AMOUNT PER POINTS


    while($total_amount <= $request_amount){ 

        $points = $points+0.50; //POINTS INCREMENTING BY 0.5

        $total_amount = $points * $amount_perpoints;

    }


    echo $points;

由于你數(shù)到它達(dá)到期望的點(diǎn),它的靈魂是少或等于。它給出的輸出為 : 5.5


查看完整回答
反對(duì) 回復(fù) 2022-09-17
  • 4 回答
  • 0 關(guān)注
  • 176 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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