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

Super regexp to format numbers

Thread Next
From:
Alexandre Jousset
Date:
August 28, 2006 09:13
Subject:
Super regexp to format numbers
Message ID:
44F3162E.1080007@gtmp.org
	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...

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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About