# File lib/ruby_units/ruby-units.rb, line 347
  def to_s(target_units=nil)
    out = @output[target_units] rescue nil
    if out
      return out
    else
      case target_units
      when :ft:
        inches = self.to("in").scalar.to_int
        out = "#{(inches / 12).truncate}\'#{(inches % 12).round}\""
      when :lbs:
        ounces = self.to("oz").scalar.to_int
        out = "#{(ounces / 16).truncate} lbs, #{(ounces % 16).round} oz"
      when String
        begin #first try a standard format string
          target_units =~ /(%[\w\d#+-.]*)*\s*(.+)*/
          out = $2 ? self.to($2).to_s($1) : "#{($1 || '%g') % @scalar || 0} #{self.units}".strip
        rescue #if that is malformed, try a time string
          out = (Time.gm(0) + self).strftime(target_units)
        end
      else
        out = case @scalar
        when Rational : 
          "#{@scalar} #{self.units}"
        else
          "#{'%g' % @scalar} #{self.units}"
        end.strip
      end
      @output = {target_units => out}
      return out
    end    
  end