工作在我把用於計算價格這個代碼中的函數getPrecio
。
對於產品和價格低於1(例如0.2或0.02),此功能不起作用
爲什麼
此其代碼:?
function getPrecio($p)
{
if($p > 0 && $p <= 1) return $p*1.99;
}
它是一個PHP代碼 當我說不行那就是它不會更正計算的價格。
嘗試這個,而不是計算
function getPrecio($p)
{
$floatPrice = floatval($p);
if($floatPrice > 0 && $floatPrice <= 1) return $floatPrice *1.99;
//if($p > 0 && $p <= 1) return $p*1.99;
elseif($p > 1 && $p <= 3) return $p*1.95;
更新的代碼
function getPrecio($p)
{
$floatPrice = floatval($p);
$floatCalculatedResult = 0;
if (between($floatPrice, 0, 1)) {
$floatCalculatedResult = $floatPrice * 1.99;
} else if (between($floatPrice, 1, 3)) {
$floatCalculatedResult = $floatPrice * 1.95;
} else if (between($floatPrice, 3, 5)) {
$floatCalculatedResult = $floatPrice * 1.90;
} else if (between($floatPrice, 5, 10)) {
$floatCalculatedResult = $floatPrice * 1.70;
} else if (between($floatPrice, 10, 20)) {
$floatCalculatedResult = $floatPrice * 1.60;
} else if (between($floatPrice, 20, 30)) {
$floatCalculatedResult = $floatPrice * 1.56;
} else if (between($floatPrice, 30, 50)) {
$floatCalculatedResult = $floatPrice * 1.52;
} else if (between($floatPrice, 50, 80)) {
$floatCalculatedResult = $floatPrice * 1.49;
} else if (between($floatPrice, 80, 100)) {
$floatCalculatedResult = $floatPrice * 1.45;
} else if (between($floatPrice, 100, 130)) {
$floatCalculatedResult = $floatPrice * 1.40;
} else if (between($floatPrice, 130, 200)) {
$floatCalculatedResult = $floatPrice * 1.39;
} else if (between($floatPrice, 200, 250)) {
$floatCalculatedResult = $floatPrice * 1.35;
} else if (between($floatPrice,250, 500)) {
$floatCalculatedResult = $floatPrice * 1.32;
} else if (between($floatPrice, 500, 700)) {
$floatCalculatedResult = $floatPrice * 1.28;
} else if (between($floatPrice, 700, 900)) {
$floatCalculatedResult = $floatPrice * 1.26;
} else if (between($floatPrice, 900, 1000)) {
$floatCalculatedResult = $floatPrice * 1.25;
} else if (between($floatPrice, 1000, 10000)) {
$floatCalculatedResult = $floatPrice * 1.15;
}
return $floatCalculatedResult;
}
function between($var, $from, $to)
{
return ($var > $from && $var <= $to);
}
更新時,如果0,02改變字段CSV〜0.02代碼工作。但是,因工作需要與0,02
這是什麼編程語言?你的意思是「不起作用」? –
獨立於這是什麼語言,也許你遇到了運算符優先級問題。是否(($ p> 0)&&($ p <= 1))'修復了它? – twalberg
雙(())不解決問題 – vandark