SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Outputting Currency Value from MySQL

    I've created a Rails app for our intranet - a simple client tracking tool. One of the client fields I have is the monthly fee they pay for our services. In MySQL, I have this stored as a decimal type (5,2). However, when I output this in my .rhtml template, it only shows the first place after the decimal.

    Example ...
    <td>Monthly Bill</td><td>$<%= client.bill %></td>
    ...

    It is showing as "30.0" instead of "30.00".

    I checked the Ruby references but couldn't find a method to output a fload to a certain precision. Any ideas?

  2. #2
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Location
    Murcia, Spain
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Luke's right,

    This is how I did it for the first rails app I'm working on. Works very nicely so far. Now I'd like to know how to make the currency symbol dynamic depending on the currency the user uses....

    Code:
      def tommorrow
     number_to_currency(ActiveRecord::Base.connection.select_one('select sum(amount) from flows where datewhen < date_add(current_timestamp, interval 1 day)')['sum(amount)'], :unit => "&euro;")
     end

  4. #4
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You guys rock ... I'm lovin' this forum.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •