Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting currency from mySQL using PHP

Status
Not open for further replies.

tyktok

Programmer
Jun 25, 2002
3
GB
I know this is gonna turn out to be really simple to do but it is just not working for me.

I need to format numbers such as the following:

9600
42000
135995

To look like:

£9,600
£42,000
£135,995

Please help, cheers.
 
I'll assume from your post you don't need help getting the pound-sterling symbol ahead of the numbers.

If your installation of PHP has perl-compatible regular expressions enabled, here's a snippet that will put commas in numbers:

[tt]<?php

$foo = 350000;
$foo = strrev ($foo);
$foo = preg_replace (&quot;/(\d\d\d)(?=\d)(?!\d*\.)/&quot;, &quot;\\1,&quot;, $foo);
$foo = strrev ($foo);

print $foo;

?>[/tt] ______________________________________________________________________
Did you know?
The quality of our answers is directly proportional to the number of stars you vote?
 
Thanks a lot sleipnir214 , that worked a treat.
 
why not just use number_format($number);

:) ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
That might work, too.
______________________________________________________________________
Did you know?
The quality of our answers is directly proportional to the number of stars you vote?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top