Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!bcm!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Printing Numbers with commas in them Keywords: commas formatting Message-ID: <1991Feb01.153709.18659@convex.com> Date: 1 Feb 91 15:37:09 GMT References: <389@cti1.UUCP> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 32 Nntp-Posting-Host: pixel.convex.com From the keyboard of kmeek@cti1.UUCP (Kevin Meek): :Is there an easy way to print numbers formatted with commas that I have :missed in the manuals? Page 233 of the book. :-) Well, that's for integers. For floats, you will wish to futz around a bit. :If not does anyone have a subroutine that will do it in an effective manner? As opposed to in an ineffective one? :-) If $_ contains the number (like 12345678.12), this works: 1 while s/(.*\d)(\d{3})/$1,$2/; Note that with floating point numbers, you might get more than you bargained for unless you do something like $_ = sprintf("%10.2f", $_) to discard boring bits. Without the sprintf you get this: 12,345,678.11,999,999,918 which you probably don't want. Continental notation may be achieved this way: s/\./\,/; 1 while s/(.*\d)(\d{3})/$1.$2/; --tom -- "Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now he can finally have the whole O/S built-in to his editor like he always wanted!" --me (Tom Christiansen )