Is there a way with PHP to show 2 (or x) decimal places, but not show the .00 if whole number?
I’ve looked at number_format, but it doesn’t look like it accommodates this exactly.. though I would like the commas every 3 non-decimal places
34.00 => 34
34.7 => 34.70
12424.9=> 12,424.90
My numbers are stored as floats w/ 2 decimal places in the database so I don’t necessarily need that
What you could do is check if it’s a whole number first, by rounding it using floor() and checking whether that’s equal to the full decimal version.
or
Another option is to use money_format():
or