PHP show only significant (non-zero) decimals

前端 未结 11 1270
借酒劲吻你
借酒劲吻你 2021-01-07 19:32

In PHP (using built-in functions) I\'d like to convert/format a number with decimal, so that only the non-zero decimals show. However, another requirement of mine is that if

11条回答
  •  北荒
    北荒 (楼主)
    2021-01-07 19:48

    rtrim($value, "0") almost works. The problem with rtrim is that it leaves 9.000 as 9.

    So just rtrim($value, "0.") and you're done.

提交回复
热议问题