From: Robert Klemme Date: 2005-09-25T02:26:41+09:00 Subject: Re: cannot convert Float into String Devin Mullins wrote: > Robert Klemme wrote: > >> Nick wrote: >> >>> i am making a pdf file, retrieving an product for the db and print >>> the price in the pdf >>> >>> @product = Product.find(@params["id"]) >>> >>> pdf.SetFont('Arial','',10) >>> pdf.Cell(3,h, "?",0,0) >>> pdf.Cell(100,h, " " + @product.price , 0,1) >> >> >> pdf.Cell(100,h, @product.price.to_s , 0,1) >> pdf.Cell(100,h, " %4.1f" % @product.price , 0,1) >> pdf.Cell(100,h, sprintf(" %4.1f", @product.price) , 0,1) > > Add to that: > pdf.Cell(100,h, "#{@product.price}", 0,1) Although I agree to the rest of your posting this variant is inefficient if you just want to convert a float into a string. $ ruby -r benchmark -e 'x=1.34;Benchmark.bm(20) {|bm| bm.report("to_s") {10000.times{ x.to_s }}; bm.report("##"){10000.times{"#{x}" }} }' user system total real to_s 0.438000 0.000000 0.438000 ( 0.430000) ## 0.500000 0.000000 0.500000 ( 0.491000) Kind regards robert