From: Daniel Sheppard Date: 2005-09-13T12:41:10+09:00 Subject: Re: Quick question. Something like: |[-1, -5.5, -44, -3.4432, 33.33].each { |x| puts sprintf("%12.5f", x) } | -1.00000 | -5.50000 | -44.00000 | -3.44320 | 33.33000 or maybe |[-1, -5.5, -44, -3.4432, 33.33].each { |x| puts sprintf("%1s%12.5f", x < 0 ? '-' : ' ', x.abs) } |- 1.00000 |- 5.50000 |- 44.00000 |- 3.44320 | 33.33000 or maybe: |[-1, -5.5, -44, -3.4432, 33.33].each { |x| puts sprintf("%+5.5f", x).sub('+',' ') } |-1.00000 |-5.50000 |-44.00000 |-3.44320 | 33.33000 -----Original Message----- From: Kevin Brown [mailto:blargity@gmail.com] Sent: Tuesday, 13 September 2005 1:25 PM To: ruby-talk ML Subject: Quick question. Alright, I feel like an absolute idiot, but the question is simple, and 30 minutes of looking hasn't yet yeilded the answer. I want to take a float (say 0.0) and output it with a space in front if it's positive, - in front if it's negative, and be able to specify how many numbers after the decimal get printed (padding with zeros). This will be used to output currency, and I just know there's a simple way to do it with Ruby, but not finding it. :-) Sorry to bother you all. ##################################################################################### This email has been scanned by MailMarshal, an email content filter. #####################################################################################