Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: (Golf) Formatting Integer To Money

by xylus (Pilgrim)
on Aug 29, 2002 at 17:36 UTC ( [id://193834]=note: print w/replies, xml ) Need Help??


in reply to Re: (Golf) Formatting Integer To Money
in thread (Golf) Formatting NumberTo Money

Why the need for sprintf ?? Am I missing something of importance?

If sprintf is not needed, here is one at 49 chars....
sub a{$_=pop;{s/(\d)(\d{3})(?!\d)/$1,$2/&&redo}$_.'.00'}
update: I am a little confused about the input, the post asks for an integer, which would not have any decimal places, but some of the input has a decimal place..
Should this handle input with decimal places, or should it just trust that the user submits integers only?
perl -e '$_=$0;split??;chop$_;$;=pop@_;$;++for(0..9060420);$_.=reverse +$;;print'

Replies are listed 'Best First'.
Re: Re: Re: (Golf) Formatting Integer To Money
by enoch (Chaplain) on Aug 29, 2002 at 17:41 UTC
    To get the precision correct. Your script fails if you input 1234.56.

    ++Abigail-II

    enoch

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://193834]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-09-18 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (24 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.