How to print integers so that they get thousands separated by underscores
How to print integers so that they get thousands separated by underscores
am 19.10.2007 19:32:36 von Ignoramus5114
3526742821 -- this number is hard to read.
I want numbers printed with underscores like this:
3_526_742_821
is there a function or a module that does this. Thanks
i
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 19:36:38 von it_says_BALLS_on_your forehead
On Oct 19, 1:32 pm, Ignoramus5114
wrote:
> 3526742821 -- this number is hard to read.
>
> I want numbers printed with underscores like this:
>
> 3_526_742_821
>
Yes, just adapt the common "commify" sub to use underscores rather
than commas.
(untested)
sub underscorify {
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1_/g;
return scalar reverse $text;
}
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 19:38:49 von jurgenex
Ignoramus5114 wrote:
Dear fivethousandonehundredfourteenth incarnation of Ignoramus
> I want numbers printed with underscores like this:
>
> 3_526_742_821
>
> is there a function or a module that does this. Thanks
Is there anything wrong with the answer to FAQ
"How can I output my numbers with commas added?"
Or do you have problems replacing the comma with an underscore in that
answer?
Don't bother answering. Right back into the killfile with number 5114, too.
jue
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 19:38:56 von 1usa
Ignoramus5114 wrote in
news:yJOdnVT9f8upd4XanZ2dnUVZ_judnZ2d@giganews.com:
> 3526742821 -- this number is hard to read.
>
> I want numbers printed with underscores like this:
>
> 3_526_742_821
>
> is there a function or a module that does this.
You know, iggy, you should read the docs once in a while:
perldoc -q "How can I output my numbers with commas added?
I know, it is my fault for not being able to figure out how to killfile all
your future incarnations, but I am getting tired of the infinite variations
in names.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines:
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 19:47:26 von Ignoramus5114
On 2007-10-19, A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> Ignoramus5114 wrote in
> news:yJOdnVT9f8upd4XanZ2dnUVZ_judnZ2d@giganews.com:
>
>> 3526742821 -- this number is hard to read.
>>
>> I want numbers printed with underscores like this:
>>
>> 3_526_742_821
>>
>> is there a function or a module that does this.
>
> You know, iggy, you should read the docs once in a while:
>
> perldoc -q "How can I output my numbers with commas added?
Thanks! Now I know what FAQ question I should have asked.
> I know, it is my fault for not being able to figure out how to killfile all
> your future incarnations, but I am getting tired of the infinite variations
> in names.
>
> Sinan
>
Try a xnews FAQ.
i
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 19:47:45 von Ignoramus5114
On 2007-10-19, it_says_BALLS_on_your forehead wrote:
> On Oct 19, 1:32 pm, Ignoramus5114
> wrote:
>> 3526742821 -- this number is hard to read.
>>
>> I want numbers printed with underscores like this:
>>
>> 3_526_742_821
>>
>
> Yes, just adapt the common "commify" sub to use underscores rather
> than commas.
>
> (untested)
>
> sub underscorify {
> my $text = reverse $_[0];
> $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1_/g;
> return scalar reverse $text;
> }
>
>
That's wonderful, thanks a lot.
i
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 20:14:03 von Paul Lalli
On Oct 19, 1:47 pm, Ignoramus5114
wrote:
> Thanks! Now I know what FAQ question I should have asked.
Out of pure curiousity, are you aware you can get a listing of ALL the
Perl FAQs, without having to know any keywords?
Type
perldoc perlfaq
into your command line. It will give you a list of all the questions,
as well as the number of the FAQ that each one is found in, so you can
read the answer.
Paul Lalli
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 20:17:25 von Ignoramus5114
On 2007-10-19, Paul Lalli wrote:
> On Oct 19, 1:47 pm, Ignoramus5114
> wrote:
>> Thanks! Now I know what FAQ question I should have asked.
>
> Out of pure curiousity, are you aware you can get a listing of ALL the
> Perl FAQs, without having to know any keywords?
>
> Type
> perldoc perlfaq
> into your command line. It will give you a list of all the questions,
> as well as the number of the FAQ that each one is found in, so you can
> read the answer.
>
> Paul Lalli
>
I had no idea. I am going to add this to my computer notes file, it is
highly useful. Thanks.
i
Re: How to print integers so that they get thousands separated by underscores
am 19.10.2007 20:31:44 von 1usa
Paul Lalli wrote in news:1192817643.190157.130100
@v23g2000prn.googlegroups.com:
> On Oct 19, 1:47 pm, Ignoramus5114
> wrote:
>> Thanks! Now I know what FAQ question I should have asked.
>
> Out of pure curiousity, are you aware you can get a listing of ALL the
> Perl FAQs, without having to know any keywords?
I recommend reading the FAQ (not necessarily in detail, maybe just
skimming) every time one installs a new Perl distribution.
I recommend looking at the relevant sections of the FAQ to see if any of
the headings are relevant to one's problem.
The form
perldoc -q "faq heading"
is a short hand for referring someone else to a given FAQ item.
> Type
> perldoc perlfaq
> into your command line.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: