Tuesday, June 27, 2006

printf reborn

I was looking for ways to format the Ruby output and lone-behold, bumped into an old friend - printf.

printf "%3.2f\n", 2.0 / 3.0

Output:
0.67
(and a big grin on my face)

The escape character for escaping the newline works only on double quotes and together with printf, gives me the comfort of knowing that a bit of c/Java syntax is still at the heart of Ruby.

0 Comments:

Post a Comment

<< Home