Hi there I am going to calculate VAT at one of my websites, and UK VAT is 17.5 %. So the question is how to round up some value to two decimal points? I often get values like 6,991.. In php I was using round function round($price, 2) is in ruby something similat to PHP''s round function where I could specify number of decimal places ? P. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 9/16/07, pgega <gega.pawel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi there > > I am going to calculate VAT at one of my websites, and UK VAT is 17.5 > %. > So the question is how to round up some value to two decimal points?one way is to use round(n * 100) / 100.0 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 9/16/07, kendear <summercoolness-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 9/16/07, pgega <gega.pawel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi there > > > > I am going to calculate VAT at one of my websites, and UK VAT is 17.5 > > %. > > So the question is how to round up some value to two decimal points? > > > one way is to use round(n * 100) / 100.0 > > >in Ruby, it is like (n * 100).round / 100.0 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, And which part of the code corresponds for the number of decimal places I want to round? (I am sorry sorry for killing you, I am just a small designer.) On Sep 16, 4:20 pm, kendear <summercooln...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/16/07, kendear <summercooln...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On 9/16/07, pgega <gega.pa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi there > > > > I am going to calculate VAT at one of my websites, and UK VAT is 17.5 > > > %. > > > So the question is how to round up some value to two decimal points? > > > one way is to use round(n * 100) / 100.0 > > in Ruby, it is like (n * 100).round / 100.0--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sep 16, 8:54 am, pgega <gega.pa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks, > > And which part of the code corresponds for the number of decimal > places I want to round? > > > in Ruby, it is like (n * 100).round / 100.0it is like (n * 10**2).round / (10**2).to_f the 2 is the one you want and 10**2 is 10 to the power of 2. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
n would be your number, then multiplying it by 100 and rounding it would round it to 2 decimal places, then divide it by 100 to get your decimal back... n = 12.3456 n * 100 = 1234.56 round(n) = 1235 1235 / 100 = 12.35 pgega wrote:> Thanks, > > And which part of the code corresponds for the number of decimal > places I want to round? > (I am sorry sorry for killing you, I am just a small designer.) > > On Sep 16, 4:20 pm, kendear <summercooln...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On 9/16/07, kendear <summercooln...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> >> >> >>> On 9/16/07, pgega <gega.pa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Hi there >>>> >>>> I am going to calculate VAT at one of my websites, and UK VAT is 17.5 >>>> %. >>>> So the question is how to round up some value to two decimal points? >>>> >>> one way is to use round(n * 100) / 100.0 >>> >> in Ruby, it is like (n * 100).round / 100.0 >> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
and as I assume n is my value I want to round ? On Sep 16, 5:01 pm, Summercool <Summercooln...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 16, 8:54 am, pgega <gega.pa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks, > > > And which part of the code corresponds for the number of decimal > > places I want to round? > > > > in Ruby, it is like (n * 100).round / 100.0 > > it is like (n * 10**2).round / (10**2).to_f > > the 2 is the one you want and 10**2 is 10 to the power of 2.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry, line 3 should be n.round() William Pratt wrote:> n would be your number, then multiplying it by 100 and rounding it > would round it to 2 decimal places, then divide it by 100 to get your > decimal back... > > n = 12.3456 > n * 100 = 1234.56 > round(n) = 1235 > 1235 / 100 = 12.35 > > pgega wrote: >> Thanks, >> >> And which part of the code corresponds for the number of decimal >> places I want to round? >> (I am sorry sorry for killing you, I am just a small designer.) >> >> On Sep 16, 4:20 pm, kendear <summercooln...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> On 9/16/07, kendear <summercooln...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> >>> >>> >>> >>> >>>> On 9/16/07, pgega <gega.pa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> Hi there >>>>> >>>>> I am going to calculate VAT at one of my websites, and UK VAT is 17.5 >>>>> %. >>>>> So the question is how to round up some value to two decimal points? >>>>> >>>> one way is to use round(n * 100) / 100.0 >>>> >>> in Ruby, it is like (n * 100).round / 100.0 >>> >> >> >> >> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> n = 12.3456 > n * 100 = 1234.56 > round(n) = 1235 > 1235 / 100 = 12.35So clear , so easy. Thanks a lot. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- prettyNum digits=0 not compatible with scientific notation
- prettyNum digits=0 not compatible with scientific notation
- Decimal
- Geometry delaunayn and deldir results, differing results from Octave due to decimal precision?
- Geometry delaunayn and deldir results, differing results from Octave due to decimal precision?