I''m trying to figure out the best way (and hopefully leanest) to conditionally have precision to a float number. Here''s what I''m doing... I have a float (which has a default precision of 1) so like 250.0 What I want to do is have the precision go to 0 if the value after the . is 0 = so 250.0 would show as 250, but 250.5 would show 250.5. Thoughts? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Write a simple helper method that returns the rounded number if
different
def display_float(num)
if num.floor < num
return num
end
return num.floor
end
On Dec 31, 5:18 pm, blaine
<jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''m trying to figure out the best way (and hopefully leanest) to
> conditionally have precision to a float number.
>
> Here''s what I''m doing...
>
> I have a float (which has a default precision of 1) so like 250.0
>
> What I want to do is have the precision go to 0 if the value after
> the . is 0 = so 250.0 would show as 250, but 250.5 would show 250.5.
>
> Thoughts? Thanks.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Brewpoo - sweet! Thanks. On Dec 31, 5:32 pm, brewpoo <jloch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Write a simple helper method that returns the rounded number if > different > > def display_float(num) > if num.floor < num > return num > end > return num.floor > end > > On Dec 31, 5:18 pm, blaine <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m trying to figure out the best way (and hopefully leanest) to > > conditionally have precision to a float number. > > > Here''s what I''m doing... > > > I have a float (which has a default precision of 1) so like 250.0 > > > What I want to do is have the precision go to 0 if the value after > > the . is 0 = so 250.0 would show as 250, but 250.5 would show 250.5. > > > Thoughts? Thanks.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---