T
Toki Toki
Hi all!
I'm testing the functionality of sprintf and I know that I can use it in
two way:
sprintf("%.3f", "1.2345")
=> "1.234"
Or
"%.3f" % "1.2345"
=> "1.234"
In the second example, what does mean the percent symbol (%) between
"%.3f" and "1.2345"? It means apply format string "%.3f" to string
"1.2345"? What I want to know is, the percent symbol is limited to
sprintf or it has a more general use in ruby?
I've searched on the ruby pickaxe and several other ruby books but I
haven't found anything on the % alone, obviously there are many use of
that combined with option (array: %w, string: %q,%Q, regexp: %r, ...).
Thanks.
Best regards.
I'm testing the functionality of sprintf and I know that I can use it in
two way:
sprintf("%.3f", "1.2345")
=> "1.234"
Or
"%.3f" % "1.2345"
=> "1.234"
In the second example, what does mean the percent symbol (%) between
"%.3f" and "1.2345"? It means apply format string "%.3f" to string
"1.2345"? What I want to know is, the percent symbol is limited to
sprintf or it has a more general use in ruby?
I've searched on the ruby pickaxe and several other ruby books but I
haven't found anything on the % alone, obviously there are many use of
that combined with option (array: %w, string: %q,%Q, regexp: %r, ...).
Thanks.
Best regards.