How to display INT from MySQL to 1,000.00 format?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

How to display INT from MySQL to 1,000.00 format?

Post by zplits »

greetings to everyone.
does anyone know how to format INT variables from MySQL and display it in a page as the following format.

Example.
in my database:
field name: balance
data type: int
value: 1000

how can i format it so that i can display it in the page as P 1,000.00 ?

note: P stands for philippines peso.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: How to display INT from MySQL to 1,000.00 format?

Post by nowaydown1 »

Have a look at either:

http://us3.php.net/number_format
http://us3.php.net/money_format (If you aren't on Windows)

There's also stuff like FORMAT if you prefer to do it on the DB side:
http://dev.mysql.com/doc/refman/5.0/en/ ... ion_format
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display INT from MySQL to 1,000.00 format?

Post by zplits »

Thanks for the response. If i use the MySql side. Can i get it and display it as 1,000.00 in my page?
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: How to display INT from MySQL to 1,000.00 format?

Post by nowaydown1 »

Yes, if you do it on the DB side, the raw result you get back from your query will be the formatted version (1,000.00).
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display INT from MySQL to 1,000.00 format?

Post by zplits »

ok then, What data type should i use? INT?double? or decimal?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to display INT from MySQL to 1,000.00 format?

Post by Christopher »

(#10850)
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: How to display INT from MySQL to 1,000.00 format?

Post by zplits »

I think it's best to use DECIMAL.
Post Reply