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.
On Tue, Sep 13, 2005 at 12:25:28PM +0900, Kevin Brown wrote:
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).
You can also use printf with the same format for direct output.
Kind regards
robert
路路路
Kevin Brown <blargity@gmail.com> wrote:
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.
Or you can use the % operator on a string which I like better. I.e.
"%3.2f" % 1.0 #=> " 1.00"
regards,
Brian
路路路
On 13/09/05, Robert Klemme <bob.news@gmx.net> wrote:
Kevin Brown <blargity@gmail.com> wrote:
> 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.