I have the following prices.
How these prices can be shown as millions and thousands in PHP ?
I want to have a user defined function to show these values as millions and thousands format as these prices will be dynamic.
Updated
I want to show the above values as:
So anyone can tell me how it can done so ?
Thanks.
Use number_format()
function
echo number_format("14500000", 0, '', ',');
Output
14,500,000
OR
If you want to represent price in Kilo/Million/Billion
$number = "14500000";
if ($number < 1000000) {
// Anything less than a million
$format = number_format($number);
} else if ($number < 1000000000) {
// Anything less than a billion
$format = number_format($number / 1000000, 2) . 'M';
} else {
// At least a billion
$format = number_format($number / 1000000000, 2) . 'B';
}
echo $format;
Output
14.50M
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With