List Info

Thread: Conditional Float Precision




Conditional Float Precision
user name
2007-12-31 16:18:47
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Conditional Float Precision
user name
2007-12-31 16:32:55
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...gmail.com> 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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Conditional Float Precision
user name
2007-12-31 16:50:16
Brewpoo - sweet! Thanks.

On Dec 31, 5:32 pm, brewpoo <jloch...gmail.com> 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...gmail.com> 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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )