I would like to know how can I add comma\'s to numbers. To make my question simple.
I would like to change this:
1210 views
To:
Often, if a number is big enough to have commas in it, you might want to do without any numbers after a decimal point - but if the value you are showing could ever be small, you would want to show those decimal places. Apply number_format conditionally, and you can use it to both add your commas and clip off any irrelevant post-point decimals.
if($measurement1 > 999) {
//Adds commas in thousands and drops anything after the decimal point
$measurement1 = number_format($measurement1);
}
Works well if you are showing a calculated value derived from a real world input.