第一种:

使用floatval()

 

第二种:

rtrim(rtrim($str, '0'), '.');

比如$str=2.360000; 最后会输出2.36

 

第三种使用正则:

        /**  
         * 去除多余的0  
         */   
        function del0($s)   
        {   
            $s = trim(strval($s));   
            if (preg_match('#^-?\d+?\.0+$#', $s)) {   
                return preg_replace('#^(-?\d+?)\.0+$#','$1',$s);   
            }    
            if (preg_match('#^-?\d+?\.[0-9]+?0+$#', $s)) {   
                return preg_replace('#^(-?\d+\.[0-9]+?)0+$#','$1',$s);   
            }   
            return $s;   
        } 

效果都是一样,但是第一种最简单

 

相关文章:

  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-01-28
猜你喜欢
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
相关资源
相似解决方案