PHP, Format Number to have always have 2 decimal places

前端 未结 1 604
一生所求
一生所求 2020-12-07 01:45

In PHP I have decimal numbers that may or may not have trailing zeros.

For example

 1
 1.1
43.87

How do I make sure that all these

1条回答
  •  误落风尘
    2020-12-07 02:05

    You should use number_format():

    number_format(1.1, 2);
    

    0 讨论(0)
提交回复
热议问题