From: Analogy Analogy Date: 2007-09-19T00:29:53+09:00 Subject: Re: converting text Matthew Rudy wrote: > John Joyce wrote: >> On Sep 18, 2007, at 9:48 AM, Analogy Analogy wrote: >> >>> [1.80%, 14.50%, ruby, 3.10%] >> Those are not numbers. >> They will be strings. >> If you want numbers you'll need to do some work to first remove the % >> characters and then convert them to_f (because they're conceptually >> floats) After that Ruby will by default lop off the trailing 0's >> But you won't have that % character on them. >> If you need to use that format and use it a lot, create a class for >> them. > > I believe String#to_f lops off any trailing characters. > > ie. "1.80%".to_f -> 1.8, > it does on my windows install of 1.8.5 at least. Sorry about that, true they are strings ["1.80%", "14.50%", "ruby", "3.10%"] I want to truncate the "numbers" to one decimal place and still keep the percent symbol (i.e. 1.80% >> 1.8%). However, I don't want to change any letter/words (i.e. ruby) at all. I'm new to the language and not sure if there is an easy way to accomplish this. -- Posted via http://www.ruby-forum.com/.