久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php怎么不四舍五入的保留一位小數(shù)

      方法:1、利用“*”運(yùn)算符將小數(shù)擴(kuò)大10倍,語法“$a=小數(shù)*10;”,將小數(shù)點(diǎn)向后移一位;2、用floor()對擴(kuò)大后的小數(shù)向下取整,舍去小數(shù)部分,語法“$b=floor($a);”;3、將取整后的數(shù)除以10,語法“$c=$b/10;”。

      php怎么不四舍五入的保留一位小數(shù)

      本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版、DELL G3電腦

      php保留一位小數(shù)(不四舍五入)的方法

      比如3.1625取小數(shù)點(diǎn)后1位,最后1位不能四舍五入。結(jié)果:3.1

      在php中,可以使用floor 函數(shù)實(shí)現(xiàn)不四舍五入的保留一位小數(shù)。

      floor 函數(shù)的作用使用舍去取整。

      例如,floor(4.66456) 結(jié)果:4 ;floor(9.1254) 結(jié)果9 。

      因此,去小數(shù)點(diǎn)后1位,需要先乘以10,然后舍去取整,再除以10,即:

      $a=小數(shù)*10; $b=floor($a); $c=$b/10;

      直接簡化為:

      floor(小數(shù)*10)/10

      示例:

      <?php header('content-type:text/html;charset=utf-8');    echo (floor(3.1625*10)/10)."<br>"; echo (floor(0.5985*10)/10)."<br>"; echo (floor(1.1425*10)/10)."<br>"; ?>

      php怎么不四舍五入的保留一位小數(shù)

      擴(kuò)展知識(shí):保留小數(shù)點(diǎn)后幾位(四舍五入)的方法

      1、round 函數(shù)

      round(小數(shù),保留位數(shù))

      2、sprintf 函數(shù)

      sprintf("%01.位數(shù)值f", 小數(shù))

      實(shí)現(xiàn)四舍五入,并且如果是不帶小數(shù)位數(shù)的,會(huì)自動(dòng)用指定的字符(指定的0)補(bǔ)至指定的小數(shù)位數(shù)

      echo sprintf("%01.2f", 5.228);  //  5.23 echo sprintf("%01.2f", 5.224);  //  5.22 echo sprintf("%01.2f", 5);      //  5.00

      3、number_format 函數(shù)

      number_format(小數(shù),保留位數(shù))

      如果是不帶小數(shù)位數(shù)的,會(huì)自動(dòng)用0補(bǔ)至指定的小數(shù)位數(shù)

      echo number_format(5.228,2);    //  5.23 echo number_format(5.224,2);    //  5.22 echo number_format(5,2);        //  5.00

      推薦學(xué)習(xí):《PHP視頻教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號