PHP dropping decimals without rounding up

前端 未结 13 2275
独厮守ぢ
独厮守ぢ 2020-12-09 15:09

I want to drop off decimals without rounding up. For example if I have 1.505, I want to drop last decimal and value should be 1.50. Is there such a function in PHP?

13条回答
  •  再見小時候
    2020-12-09 15:36

    $num = 118.74999669307;
    $cut = substr($num, 0, ((strpos($num, '.')+1)+2));`
    // Cut the string from first character to a length of 2 past the decimal.
    / substr(cut what, start, ( (find position of decimal)+decimal itself)+spaces after decimal) )
    echo $cut; 
    

    this will help you shorten the float value without rounding it..

提交回复
热议问题