I am using the number to currency function because i live in the uk and
the company want me to only show values of the pound of course.I have
created all my application using ruby script/generate
scaffold_resource.... I have come across with a problem... this code is
in my applcation:
def number_to_currency(number, options = {})
options = options.stringify_keys
precision, unit, separator, delimiter = options.delete("precision")
{
2
}, options.delete("unit") { "£" },
options.delete("separator") { "." },
options.delete("delimiter") { "," }
separator = "" unless precision > 0
begin
parts = number_with_precision(number,
precision).split(''.'')
unit + number_with_delimiter(parts[0], delimiter) + separator +
parts[1].to_s
rescue
number
end
end
it definately should work, but why doesnt the £ sign come as a question
mark I have also tryed:
def number_to_currency_gbp (number)
number_to_currency(number, { :unit => "£"})
end
This doesnt work either it is not picking up the £ how can i solve
this problem thanks
--
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
this works for me.. <%= number_to_currency(12.65, :unit => "£") %> returns => £12.65 does that help? On Dec 6, 6:45 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am using the number to currency function because i live in the uk and > the company want me to only show values of the pound of course.I have > created all my application using ruby script/generate > scaffold_resource.... I have come across with a problem... this code is > in my applcation: > > def number_to_currency(number, options = {}) > options = options.stringify_keys > precision, unit, separator, delimiter = options.delete("precision") { > 2}, options.delete("unit") { "£" }, options.delete("separator") { "." }, > > options.delete("delimiter") { "," } > separator = "" unless precision > 0 > begin > parts = number_with_precision(number, precision).split(''.'') > unit + number_with_delimiter(parts[0], delimiter) + separator + > parts[1].to_s > rescue > number > end > end > > it definately should work, but why doesnt the £ sign come as a question > mark I have also tryed: > > def number_to_currency_gbp (number) > number_to_currency(number, { :unit => "£"}) > end > > This doesnt work either it is not picking up the £ how can i solve > this problem thanks > -- > Posted viahttp://www.ruby-forum.com/.y-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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
crap, Google converted it for me. I meant this (take out the ''_remove_''s): <%= number_to_currency(12.65, :unit => "&_remove_pound_remove_;") %> On Dec 6, 10:25 am, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> this works for me.. > > <%= number_to_currency(12.65, :unit => "£") %> > returns => £12.65 > > does that help? > > On Dec 6, 6:45 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > I am using the number to currency function because i live in the uk and > > the company want me to only show values of the pound of course.I have > > created all my application using ruby script/generate > > scaffold_resource.... I have come across with a problem... this code is > > in my applcation: > > > def number_to_currency(number, options = {}) > > options = options.stringify_keys > > precision, unit, separator, delimiter = options.delete("precision") { > > 2}, options.delete("unit") { "£" }, options.delete("separator") { "." }, > > > options.delete("delimiter") { "," } > > separator = "" unless precision > 0 > > begin > > parts = number_with_precision(number, precision).split(''.'') > > unit + number_with_delimiter(parts[0], delimiter) + separator + > > parts[1].to_s > > rescue > > number > > end > > end > > > it definately should work, but why doesnt the £ sign come as a question > > mark I have also tryed: > > > def number_to_currency_gbp (number) > > number_to_currency(number, { :unit => "£"}) > > end > > > This doesnt work either it is not picking up the £ how can i solve > > this problem thanks > > -- > > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi thanks for that i have tried this and it does work, but what if i was using active scaffold? how do i get around this as it compeltely ignores it -- 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 -~----------~----~----~----~------~----~------~--~---