irb(main):006> '%{amount}.2f' % { amount: 100.0 }
=> "100.0.2f"
irb(main):007> "%<amount>.2f" % { amount: 100.0 }
=> "100.00"
In Ruby, string formatting using %{}
and %<>
is part of the Kernel#sprintf
method. These formatting options are explained in the Ruby documentation under the Kernel
module. If just like me you were surprised by this code, check the docs for this one and much more.