Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Can I pad a number with leading spaces rather than leading 0's

by greywolf (Priest)
on Aug 21, 2001 at 00:16 UTC ( [id://106350]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-28 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found