负PHP值的小数

负PHP值的小数,php,jquery,Php,Jquery,我正在编写一些php代码来输出一个随机值 $max_mal = (3 - $oray); $oray = 1; $max = 100; $total = 0; for ($i = 0; $i < $max_mal; $i++){ $goli = mt_rand(3, 8); $total += $goli; $golis[] = $goli; } 我希望得到最多5个数字的十进制值,但一旦出现负值,

我正在编写一些php代码来输出一个随机值

$max_mal = (3 - $oray);
$oray       =   1;
$max        =   100;
$total = 0;
    for ($i = 0; $i < $max_mal; $i++){
      $goli = mt_rand(3, 8);
      $total += $goli;
        $golis[] = $goli;
    } 
我希望得到最多5个数字的十进制值,但一旦出现负值,结果是0.000-1,而不是-0.00001

$myresultb = str_pad($mario, 5, '0', STR_PAD_LEFT);
$myresultf =  '0.'.$myresultb.'<br/>';
$total_score = 300;
echo  $myresultf;
我想用jquery实时更新总分,只要单击了en按钮,
也会实时刷新

$("#play").click(function() {
var currentscore = $("#current_score").val();
var totalscore = $("#total_score").val();
how to do this.....
});
试试这个:

$max        =   100;
 $oray       =   1;
 $max_mal = (3 - $oray);


$total = 0;
    for ($i = 0; $i < $max_mal; $i++){
      $goli = mt_rand(3, 8);
      $total += $goli;
        $golis[] = $goli;
    } 

    foreach($golis as &$goli) {
        $goli = floor(($goli / $total) * $max);
          if ($goli == 0) {
            $goli = 1;
          }
     }
    $result =   array_pad($golis, 3, -1);
    shuffle($result);
    $myresult = $result[0];    
    $negative_var=false;

    if($myresult < 0)
    {
      $negative_var=true;

      $myresult = 0-$myresult;
    }

    $myresultb = str_pad($myresult, 5, '0', STR_PAD_LEFT);
    $myresultf =  '0.'.$myresultb.'<br/>';

    if($negative_var)
      $myresultf="-".$myresultf;

    $total_score = 300;
    echo  $myresultf;
$max=100;
$oray=1;
$max_mal=(3-$oray);
$total=0;
对于($i=0;$i<$max\u-mal;$i++){
$goli=百万兰特(3,8);
$total+=$goli;
$golis[]=$goli;
} 
foreach($golis as和$goli){
$goli=地板($goli/$total)*$max);
如果($goli==0){
$goli=1;
}
}
$result=阵列垫($golis,3,-1);
洗牌($结果);
$myresult=$result[0];
$negative_var=false;
如果($myresult<0)
{
$negative_var=true;
$myresult=0-$myresult;
}
$myresultb=str_pad($myresult,5,'0',str_pad_左);
$myresultf='0.$myresultb'
; 如果($负_var) $myresultf=“-”$myresultf; $total_得分=300; echo$myresultf;
简单使用如下:

$myresultb=str_replace('-','$myresultb);
如果($myresult==-1){
$myresultf='-0.$myresultb'
; } 否则{ $myresultf='0.$myresultb'

}
感谢您的帮助,您能否告诉我如何使用jquery而不是流行的php在
中获取
$myresultf
值,因为我想在每次单击按钮时更新此值,而不刷新页面,方法是从
数组中获取它$myresult=$result[0]为此使用ajax
 <div id="current_score"></div>
$("#play").click(function() {
var currentscore = $("#current_score").val();
var totalscore = $("#total_score").val();
how to do this.....
});
$max        =   100;
 $oray       =   1;
 $max_mal = (3 - $oray);


$total = 0;
    for ($i = 0; $i < $max_mal; $i++){
      $goli = mt_rand(3, 8);
      $total += $goli;
        $golis[] = $goli;
    } 

    foreach($golis as &$goli) {
        $goli = floor(($goli / $total) * $max);
          if ($goli == 0) {
            $goli = 1;
          }
     }
    $result =   array_pad($golis, 3, -1);
    shuffle($result);
    $myresult = $result[0];    
    $negative_var=false;

    if($myresult < 0)
    {
      $negative_var=true;

      $myresult = 0-$myresult;
    }

    $myresultb = str_pad($myresult, 5, '0', STR_PAD_LEFT);
    $myresultf =  '0.'.$myresultb.'<br/>';

    if($negative_var)
      $myresultf="-".$myresultf;

    $total_score = 300;
    echo  $myresultf;