From: Tim Hunter Date: 2008-10-23T10:03:57+09:00 Subject: Re: i need to represent data as percentages Trick Nick wrote: > basically i go through a document count up the total number of times the > status codes appeared. eg 200 = 96 201 =8 300 = 12 etc etc. I have > counted up the total number of codes in the whole file and now must > divide by each source codes value or individual count so it would be > something like 108.to_f / 92.to_f but i get these numbers such as > 0.86899 yadayadayada. How do i convert that float number now to a > representable percent such as 87%? irb(main):008:0> x = 0.86899 => 0.86899 irb(main):009:0> "%2d%%" % (x * 100.0) => "86%" irb(main):010:0> ~$ ri String#% --------------------------------------------------------------- String#% str % arg => new_str ------------------------------------------------------------------------ Format---Uses str as a format specification, and returns the result of applying it to arg. If the format specification contains more than one substitution, then arg must be an Array containing the values to be substituted. See Kernel::sprintf for details of the format string. "%05d" % 123 #=> "00123" "%-5s: %08x" % [ "ID", self.id ] #=> "ID : 200e14d6" ~$ -- RMagick: http://rmagick.rubyforge.org/