问题描述
我正在编写一些php代码以输出随机值
I am writing a bit of php code to output a random value
$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;
}
每个循环都在这里
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];
我希望获取最多5个数字的十进制值,但是一旦出现负值,结果将是0.000-1,而不是-0.00001
I am looking to get decimal values upto 5 numbers, but once a negative value comes it results out as 0.000-1 instead of -0.00001
$myresultb = str_pad($mario, 5, '0', STR_PAD_LEFT);
$myresultf = '0.'.$myresultb.'<br/>';
$total_score = 300;
echo $myresultf;
第二,我是php学习的新手,所以我是否正确地编写了PHP或需要改进
Secondly I am new to php learning so am I doing this PHP correct or it needs improvement
我有一个div来显示这样的总得分
I have a div to show total score like this
<div id="total_score"></div>
和另一个div显示当前得分,其值为echo $myresultf;
and another div to show current score which value comes as echo $myresultf;
<div id="current_score"></div>
我想在单击甚至按钮并同时实时刷新<?php echo $myresultf ?>
时使用jquery实时更新总分
I want to update total score in real time with jquery wheneven button is clicked and <?php echo $myresultf ?>
is refreshed in real time also
$("#play").click(function() {
var currentscore = $("#current_score").val();
var totalscore = $("#total_score").val();
how to do this.....
});
推荐答案
简单用法如下:
$myresultb =str_replace('-','',$myresultb);
if($myresult == -1) {
$myresultf = '-0.'.$myresultb.'<br/>';
}
else {
$myresultf = '0.' . $myresultb . '<br/>';
}
这篇关于小数表示负PHP值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!