in reply to Re: Can I pad a number with leading spaces rather than leading 0's
in thread Can I pad a number with leading spaces rather than leading 0's

Oops, I missed the formatting of my results list (multiple spaces are ignored yadda yadda yadda) but you nailed it. I am looking for the all $'s to line up on the left and all the decimal places to line up on the right.

sprintf("\$%08.2f", $price) formats the way I want to but I don't want to see the 0's.

sprintf("\$%8.2f", $price) seems to forget about the padding up front.

mr greywolf
  • Comment on Re: Re: Can I pad a number with leading spaces rather than leading 0's

Replies are listed 'Best First'.
Re: Re: Re: Can I pad a number with leading spaces rather than leading 0's
by chipmunk (Parson) on Aug 21, 2001 at 00:23 UTC
    sprintf("\$%8.2f", $price) seems to forget about the padding up front.
    Works fine for me:
    #!perl $price = 16.50; $formatted = sprintf("\$%8.2f", $price); print "Price is $price, formatted price is $formatted.\n"; __END__ Price is 16.5, formatted price is $ 16.50.
Re: Re: Re: Can I pad a number with leading spaces rather than leading 0's
by HyperZonk (Friar) on Aug 21, 2001 at 02:07 UTC
    Please clarify what you mean by "seems to forget." You seem to be saying that the spaces don't appear. Hmmmm ... just a thought ... are you using this to print to a web page, i.e., in HTML? You know, extra spaces don't appear in HTML unless you surround them with pre tags or similar formatting mechanisms.

    -HZ
      Thanx to everyone who responded, you guys nailed it! It was an html problem not a perl problem.

      I am now hanging my head in shame and getting several lashes with a wet noodle.

      mr greywolf