number_format() php remove trailing zeros
问题 Is there a way with number_format() to leave out decimal places if the number is not a float/decimal? For example, I would like the following input/output combos: 50.8 => 50.8 50.23 => 50.23 50.0 => 50 50.00 => 50 50 => 50 Is there a way to do this with just a standard number_format() ? 回答1: You can add 0 to the formatted string. It will remove trailing zeros. echo number_format(3.0, 1, ".", "") + 0; // 3 A Better Solution: The above solution fails to work for specific locales. So in that