PHP show only significant (non-zero) decimals

前端 未结 11 1413
借酒劲吻你
借酒劲吻你 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条回答
  •  猫巷女王i
    2021-01-07 19:47

    Assuming the number is encoded as or cast to a string, here's a general purpose approach:

    $value = is_numeric($value) ? strval($value + 0) : $value;
    

提交回复
热议问题