Hello people I''m developing a rails 3.0.9 app and I''m doing some calculations for prices. I need to do the following: if I get (i.e.) 10.0 to 10.4 I need to store 10 if I get (i.e.) 10.5 to 10.9 I need to store 11 Is there a rails way to do this?, thanks for your help -- 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 groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Nov 24, 2011 at 7:26 AM, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m developing a rails 3.0.9 app and I''m doing some calculations for > prices. > > I need to do the following: > > if I get (i.e.) 10.0 to 10.4 I need to store 10 > if I get (i.e.) 10.5 to 10.9 I need to store 11 > > Is there a rails way to do this?, thanks for your helpRuby, not Rails -- read the doc for BigDecimal, which is what you should be using for prices.> amount = BigDecimal.new("10.5")=> #<BigDecimal:101294c88,''0.105E2'',18(18)>> amount.round=> 11> amount = BigDecimal.new("10.4")=> #<BigDecimal:10128c1c8,''0.104E2'',18(18)>> amount.round=> 10 HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org about.me/hassanschroeder twitter: @hassan -- 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 groups.google.com/group/rubyonrails-talk?hl=en.
On 24 nov, 12:34, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Nov 24, 2011 at 7:26 AM, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''m developing a rails 3.0.9 app and I''m doing some calculations for > > prices. > > > I need to do the following: > > > if I get (i.e.) 10.0 to 10.4 I need to store 10 > > if I get (i.e.) 10.5 to 10.9 I need to store 11 > > > Is there a rails way to do this?, thanks for your help > > Ruby, not Rails -- read the doc for BigDecimal, which is what you > should be using for prices. > > > amount = BigDecimal.new("10.5") > > => #<BigDecimal:101294c88,''0.105E2'',18(18)>> amount.round > => 11 > > amount = BigDecimal.new("10.4") > > => #<BigDecimal:10128c1c8,''0.104E2'',18(18)>> amount.round > > => 10 > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe80Tx58lXaADg@public.gmane.org://about.me/hassanschroeder > twitter: @hassanThanks Hassan, that works for me -- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Yep, I was thinking abou to say exactaly the same thing as the guy above! For round a number I am using the bigdecimal class and the method round! I think it is the best way to do it! regards 2011/11/24 Hassan Schroeder <hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> On Thu, Nov 24, 2011 at 7:26 AM, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > I''m developing a rails 3.0.9 app and I''m doing some calculations for > > prices. > > > > I need to do the following: > > > > if I get (i.e.) 10.0 to 10.4 I need to store 10 > > if I get (i.e.) 10.5 to 10.9 I need to store 11 > > > > Is there a rails way to do this?, thanks for your help > > Ruby, not Rails -- read the doc for BigDecimal, which is what you > should be using for prices. > > > amount = BigDecimal.new("10.5") > => #<BigDecimal:101294c88,''0.105E2'',18(18)> > > amount.round > => 11 > > amount = BigDecimal.new("10.4") > => #<BigDecimal:10128c1c8,''0.104E2'',18(18)> > > amount.round > => 10 > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > about.me/hassanschroeder > twitter: @hassan > > -- > 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 > groups.google.com/group/rubyonrails-talk?hl=en. > >-- thiagocifani thiagocifani.wordpress.com twitter.com/thiagocifani del.icio.us/thiagocifani <del.icio.us/thiagocifani> -- 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 groups.google.com/group/rubyonrails-talk?hl=en.