PHP show only significant (non-zero) decimals
问题 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 it's a number without a decimal value, I'd still like to show that zero. Examples: 9.000 -> 9.0 9.100 -> 9.1 9.120 -> 9.12 9.123 -> 9.123 rtrim($value, "0") almost works. The problem with rtrim is that it leaves 9.000 as 9. . sprintf() seemed like a candidate, but I couldn't get it to have a variable amount of decimals.