powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

I've searched and searched, but don't know what to search for. can you please tell me what to search for, to format a number, say, 1000000 to add the comma's where they should be to look right, such as 1,000,000?

I've done super search, I've searched for tons of keywords, but cannot find anything that show's me how to format, even a phone number, or anything that is remotely close.

I would deeply appreciate any pointers into the right direction

thx,
Richard

Replies are listed 'Best First'.
Re: adding comma's... formatting numbers
by neuroball (Pilgrim) on Jan 31, 2004 at 07:41 UTC
Re: adding comma's... formatting numbers
by davis (Vicar) on Jan 31, 2004 at 10:13 UTC

    ....I've searched for tons of keywords....
    But did you search CPAN? Searching for format number brings up the lovely Number::Format, which does exactly what you want (look at THOUSANDS_SEP).


    davis
    It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
Re: adding comma's... formatting numbers
by bart (Canon) on Jan 31, 2004 at 10:34 UTC
Re: adding comma's... formatting numbers
by Roger (Parson) on Jan 31, 2004 at 13:24 UTC
    The following code will comma-fy floating numbers, like 10000.00 into 10,000.00. Which I think would be more useful to you than one that formats just integers.

    { local $_ = $amount; /\./ ? s/(?<=\d)(?=(\d{3})+(?:\.))/,/g : s/(?<=\d)(?=(\d{3})+(?!\d))/,/g; $amount = $_; }

Re: adding comma's... formatting numbers
by Abigail-II (Bishop) on Jan 31, 2004 at 12:18 UTC
    I've done super search, I've searched for tons of keywords, but cannot find anything that show's me how to format, even a phone number, or anything that is remotely close.
    And the answer was there on your own box all the time. It's in the perlfaq, and a simple perldoc -q commas would have revealed it.

    Abigail

Re: adding comma's... formatting numbers
by scottj (Monk) on Jan 31, 2004 at 12:11 UTC
    This seems to be the authority on the topic.