Hi, i have unique visitors and transactions in my database, wich are showed through an swf-graph. This works fine. Now i want to calculate the conversion-ratio in percentage: visitors/transactions*100= ratio in percentage Is there a function in ruby/rails to realize that? Grtz..remco -- 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-/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 27 Aug 2008, at 07:28, Remco Swoany wrote:> > Hi, > > i have unique visitors and transactions in my database, wich are > showed > through an swf-graph. This works fine. > > Now i want to calculate the conversion-ratio in percentage: > > visitors/transactions*100= ratio in percentage > > Is there a function in ruby/rails to realize that?what do want more than just doing that calculation ? The number_to_percentage helper will format it nicely if that''s what you want. Fred --~--~---------~--~----~------------~-------~--~----~ 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 Wed, Aug 27, 2008 at 8:28 AM, Remco Swoany <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > i have unique visitors and transactions in my database, wich are showed > through an swf-graph. This works fine. > > Now i want to calculate the conversion-ratio in percentage: > > visitors/transactions*100= ratio in percentage > > Is there a function in ruby/rails to realize that?I don''t know if there is a function in ruby or rails to do that, but I''m quite sure something like ratio = visitors / transaction * 100 will do the trick. p.s. : learn ruby, and a little of programming worth the effort. -- Gabriel Laskar <bibi.skuk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 27 Aug 2008, at 07:28, Remco Swoany wrote: > >> >> Is there a function in ruby/rails to realize that? > > what do want more than just doing that calculation ? The > number_to_percentage helper will format it nicely if that''s what you > want. > > FredHi, i have 2 array''s t.set_data([46,28,33,48,54,49,34,40,36,43,56,55,57,49,38,35,36,62,44,59,40,55,27,37,47,56]) v.set_data([2442,1754,2887,3378,2937,2595,2871,2508,1874, 2699,3203,3044,3034,2558,3565,2299,2917,3686,3167,2824,3308,2731,2034,2888,3526, 3434]) The calculation that i want to perform is t.set_data/v.setdata * 100 = percentage remco -- 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-/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 -~----------~----~----~----~------~----~------~--~---
I''m guessing something like this: >> x = [1,2,3] => [1, 2, 3] >> y = [5,6,7] => [5, 6, 7] >> combined = x.zip y => [[1, 5], [2, 6], [3, 7]] >> combined.each do |a,b| ?> puts a.to_f/b.to_f * 100 >> end 20.0 33.3333333333333 42.8571428571429 or once you have combined, you could easily do: percentage = combined.map{|a,b| a.to_f/b.to_f*100} Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #4 parts a and b now available! http://sensei.zenunit.com/ On 27/08/2008, at 5:09 PM, Remco Swoany wrote:> > Frederick Cheung wrote: >> On 27 Aug 2008, at 07:28, Remco Swoany wrote: >> >>> >>> Is there a function in ruby/rails to realize that? >> >> what do want more than just doing that calculation ? The >> number_to_percentage helper will format it nicely if that''s what you >> want. >> >> Fred > > Hi, > > i have 2 array''s > > t > .set_data > ([46,28,33,48,54,49,34,40,36,43,56,55,57,49,38,35,36,62,44,59,40,55,27,37,47,56 > ]) > v.set_data([2442,1754,2887,3378,2937,2595,2871,2508,1874, > 2699,3203,3044,3034,2558,3565,2299,2917,3686,3167,2824,3308,2731,2034,2888,3526 > , > 3434]) > > The calculation that i want to perform is > > t.set_data/v.setdata * 100 = percentage > > remco > > > > > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Remco Swoany wrote:> Hi, > > i have 2 array''s > > t.set_data([46,28,33,48,54,49,34,40,36,43,56,55,57,49,38,35,36,62,44,59,40,55,27,37,47,56]) > v.set_data([2442,1754,2887,3378,2937,2595,2871,2508,1874, > 2699,3203,3044,3034,2558,3565,2299,2917,3686,3167,2824,3308,2731,2034,2888,3526, > 3434]) > > The calculation that i want to perform is > > t.set_data/v.setdata * 100 = percentage > > remcoyou can try: t.each_with_index do |i,j| percentage = i/v[j] * 100 end if they''re combined ;D -- 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-/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 -~----------~----~----~----~------~----~------~--~---