我有以下代码;

$sel_referrals1="SELECT SUM(amount) as da_sum
  FROM topup WHERE user_id IN ( SELECT t1.referree
  FROM referrals AS t1
  LEFT JOIN referrals AS t2 ON t2.referrer = t1.referree
  LEFT JOIN referrals AS t3 ON t3.referrer = t2.referree
  LEFT JOIN referrals AS t4 ON t4.referrer = t3.referree
  LEFT JOIN referrals AS t5 ON t5.referrer = t4.referree
  LEFT JOIN referrals AS t6 ON t6.referrer = t5.referree
  LEFT JOIN referrals AS t7 ON t7.referrer = t6.referree
  LEFT JOIN referrals AS t8 ON t8.referrer = t7.referree
  LEFT JOIN referrals AS t9 ON t9.referrer = t8.referree
  LEFT JOIN referrals AS t10 ON t10.referrer = t9.referree
  LEFT JOIN referrals AS t11 ON t11.referrer = t10.referree
WHERE t1.referrer = '{$_SESSION['user']}')
AND YEAR(date_time) = YEAR(CURRENT_DATE())
AND MONTH(date_time) = MONTH(CURRENT_DATE())";

$selected1=mysqli_query($conn,$sel_referrals1);
$sel_level1_array=mysqli_fetch_row($selected1);
$level1=number_format($sel_level1_array[0],2);

$curYear = date('Y');
$curMonth = date('F');
$rate1 = 0.02;
$rate2 = 0.008;
$rate3 = 0.004;
$level11 = 1260.00;
$total=$level1 * $rate1;

echo $total;


$level1返回1260.00
我还有另一个变量$rate1,我声明为$rate1=0.02
我需要将$level1$rate1相乘。当我执行$level1*$rate1时,我得到0.02,

我的预期结果是25.02。我做错了什么?

最佳答案

number_format返回一个字符串

$level1=number_format($sel_level1_array[0],2);


使用floatval

$level1 = floatval($sel_level1_array[0]);

08-03 19:29