PHP number: decimal point visible only if needed

后端 未结 12 1577
死守一世寂寞
死守一世寂寞 2021-01-31 06:48

I\'d like to know if exists some function to automatically format a number by it\'s decimal, so if I have:



        
12条回答
  •  北海茫月
    2021-01-31 07:38

    I've been accused of doing something like this:

     floatval($foo) == intval($foo) ? number_format($foo) : number_format($foo,2);
    

提交回复
热议问题