The %g specifier to sprintf will do this automatically:

"%g" % 1.0
=> "1"

"%g" % 1.375
=> "1.375"

--Matt Jones

On Feb 27, 1:20 am, northband <northb...@gmail.com> wrote:
> Hi -
>
> I am working with floats and am wondering how I can trim the decimal
> and trailing zeros on my whole numbers.  For instance, whole numbers
> are being displayed as 1.0, 2.0, 3.0, etc...  I would like to remove
> the decimal and any trailing zeros with out effecting other non-whole
> number floats (ex. 1.375).
>
> Any ideas?  Help appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to