PHP show only significant (non-zero) decimals

前端 未结 11 1363
借酒劲吻你
借酒劲吻你 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 20:11

    A trailing zero is significant:

    • A value of 9.0 implies, that the real value is more than 8.9 and less than 9.1
    • A value of 9.00000 implies, that the real value is more than 8.99999 and less than 9.00001

    Therefore, your requirement is quite unusual. That's the reason why no function exists to do what you want.

提交回复
热议问题