I want to store prices like this in the mysql database:
1000
instead of like this:
10.00
And when I echo the output I want the number to be displayed with decimals and commas in the proper places. So if this is in the database:
100000
it should display as:
1,000.00
if this is in the database:
1000000
it should show as
10,000.00
and if this is in the database:
100
it should show as:
1.00
How can this be achieved?
Stored them as integers and divide by 100 when you retrieve them (and multiply by 100 when you store them). If you don’t want to do that, you might want to consider storing them as DECIMAL
You can format it using the number_format function
Prints 1,000.00 for
$number = 100000