>>>>> "AP" == A Pagaltzis <[EMAIL PROTECTED]> writes:

  AP> * Bernie Cosell <[EMAIL PROTECTED]> [2004-04-19 17:37]:
  >> So: what I want is something to format money correctly, whther
  >> it is fractional or not.  there's the fairly awful:
  >> 
  >> sprintf ($amt =~ /\.\d\d\d/? "%7.3f": "%7.2f"), $amt

  AP> Test:

  AP>     perl -le'for (@ARGV) { $_ = sprintf "%7.3f", $_; \
  AP>     chop if /\.\d\d0\z/; print; }' 1.2, 1.23, 1.234, 1.2345
  AP>       1.20
  AP>       1.23
  AP>       1.234
  AP>       1.234

 perl -lpe 's/(?<=\.\d\d)(?:0\z|[^0]\d+)//'
.1234
.12
.120
.12
.123
.123

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Reply via email to