Hi, I have a question about displaying digits in Rails. whenever I print the price of an item, if the last digit is a zero or double zeros then it doesn''t display properly. How do I display a number so that it looks like currency? thank you! -- Posted via http://www.ruby-forum.com/.
On Feb 21, 2006, at 15:16, cranberry wrote:> Hi, > > I have a question about displaying digits in Rails. > > whenever I print the price of an item, if the last digit is a zero or > double zeros then it doesn''t display properly. > > How do I display a number so that it looks like currency?There are some helpers that may be useful: number_to_currency number_with_delimiter number_with_precision See http://api.rubyonrails.org for detais. -- fxn
$ irb irb(main):001:0> i = 15.00 => 15.0 irb(main):002:0> puts i 15.0 => nil irb(main):003:0> puts "%.2f" % i 15.00 => nil -- Kent --- http://www.datanoise.com On 2/21/06, cranberry <miriamraphael@yahoo.com> wrote:> Hi, > > I have a question about displaying digits in Rails. > > whenever I print the price of an item, if the last digit is a zero or > double zeros then it doesn''t display properly. > > How do I display a number so that it looks like currency? > > thank you! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Like this: <%=h money(number) %> Of course "number" will be the name of YOUR field. Or you can do this: <% number_with_precision(number, 2) %> where 2 is the number of digits of the fraction to show. -- Posted with http://DevLists.com. Sign up and save your time!
Oops. That second example should be <%= number_with_precision(number, 2) %> On Tuesday, February 21, 2006, at 2:27 PM, Richard Williams wrote:>Like this: > ><%=h money(number) %> > >Of course "number" will be the name of YOUR field. >Or you can do this: > ><% number_with_precision(number, 2) %> > >where 2 is the number of digits of the fraction to show. > > > > > > >-- >Posted with http://DevLists.com. Sign up and save your time! >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your time!