Re: Remove trailing zeros

Juan Kinunt
Tue, 20 Apr 2010 09:46:00 -0000

And how can I remove the trailing zeros if the value is to be shown in a
text field?

I.e.:

<%= linea_form.text_field :unidades, :id =>
"invoice_line_units", :name
=> "invoice[lines_attributes][#{id_or_index}][units]", :size =>
10 %>

Matt Jones wrote:
> The %g specifier to sprintf will do this automatically:
>
> "%g" % 1.0
> => "1"
>
> "%g" % 1.375
> => "1.375"
>
> --Matt Jones

--
Posted via http://www.ruby-forum.com/.

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at