In my database I have values like
256.23, 200.33, 89.33, 133.45,
I have to multiply these values with thousand and then format the result as price(comma separated)
256.23 x 1000 = 256230 I want to show this as 256,230 200.33 x 1000 = 200330 I want this as 200,330 89.33 x 1000 = 89330 I want this as 89,330
Currently I am using formula
echo "Price is : $".$price*1000;
But how to format this, I've no idea.
For format String "%,. 2f" means separate digit groups with commas and ".
The character used as the thousands separator In the United States, this character is a comma (,). In Germany, it is a period (.). Thus one thousand and twenty-five is displayed as 1,025 in the United States and 1.025 in Germany. In Sweden, the thousands separator is a space.
You are looking for the number_format function.
$price=123456;
echo number_format($price);
// output: 123,456
This function accepts either one, two, or four parameters (not three):
If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.
If two parameters are given, number will be formatted with decimals decimals with a dot (".") in front, and a comma (",") between every group of thousands.
If all four parameters are given, number will be formatted with decimals decimals, dec_point instead of a dot (".") before the decimals and thousands_sep instead of a comma (",") between every group of thousands.
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