BubblewrapBeast
BubblewrapBeast

Reputation: 1607

Number from MySQL database to be formated with comma

So i'm currently running a php website that pulls data from a mysql database. At the moment i have a column, we can call this "views" the numbers that are in this column are just digits and not recognised as numbers and therefore have no commas to separate the numbers. So the code onsite will look something like this:

<div><b>Views: </b><?=$views?></div>

I have been able to take a column that is showing seconds to be formated in a minuite/seconds format:

<div><b>Length: </b><?=gmdate("i:s", $length)?></div>

But I am unable to find out how I can format the numbers to include commas, at the moment a number will pull as "1000000" but I would like to format it so that the user will see "1,000,000".

Thanks in advance.

p.s If you do know how to do this and know of any documentation could you link me to that also.

Solved by "Paulo Lima"

Code would look like:

Views:

Upvotes: 0

Views: 170

Answers (1)

Paulo Lima
Paulo Lima

Reputation: 76

Is this what you are looking for?

http://php.net/manual/pt_BR/function.number-format.php

number_format( $views, 0 , "." , "," );

No decimal places. Dot for decimal point, comma for thousands separator.

Upvotes: 2

Related Questions