hello i need to format the retrieved value to two decimal points in ruby. MY problem is: if the value is 15.0 i need to print it as 15.00 and if it is 12.5 it should be 12.50. please help me in this. -- 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 -~----------~----~----~----~------~----~------~--~---
In Ruby or Rails? If you are using rails, it comes with a nice helper method called number_to_currency. Use it like so, number_to_currency(15.0) or number_to_currency(variable_name) Hope that helps, Tyler Prete On 9/11/06, Ks Ben <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > hello > i need to format the retrieved value to two decimal points in ruby. MY > problem is: if the value is 15.0 i need to print it as 15.00 and if it > is 12.5 it should be 12.50. please help me in this. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
''%.2f'' % 12.5 => "12.50" Am 11.09.2006 um 11:05 schrieb Ks Ben:> > hello > i need to format the retrieved value to two decimal points in ruby. MY > problem is: if the value is 15.0 i need to print it as 15.00 and if it > is 12.5 it should be 12.50. please help me in this. > > -- > Posted via http://www.ruby-forum.com/. > > >-- Thomas Fuchs wollzelle http://www.wollzelle.com questentier on AIM madrobby on irc.freenode.net http://www.fluxiom.com :: online digital asset management http://script.aculo.us :: Web 2.0 JavaScript http://mir.aculo.us :: Where no web developer has gone before --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---