develooper Front page | perl.fwp | Postings from August 2006

Super regexp to format numbers

Thread Next
Alexandre Jousset
August 28, 2006 09:13
Super regexp to format numbers
Message ID:
	Hello list,

	I have a problem that I've solved with some logic and a few lines of 
code but I'm sure that there is a good regexp that can do the job. So I 
ask the regexp gurus of this list whether they have a solution.

	Let's start with this :

$number = 12345678.1234
$number =~ s/./,/; # change decimal point to French notation
spacify($number); # Do the magic
print "$number\n";

	and this should print :

12 345 678,1234

	For the moment I have a (too) complicated sub spacify and I would like 
to simplify it to a regexp. Is this possible ? How ? Of course we can 
use this to output the number in English notation like 
'12,345,678.1234', same thing...

	Any clue ? I'm sure this is an old problem...

--      \^/                                            --
--    -/ O \---------------------------------------    --
--   | |/ \|      Alexandre (Midnite) Jousset      |   --
--    -|___|---------------------------------------    --

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About