SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sql currency output

    I have a field that I'd like the sql code to format as currency. ie. table1.field1 = 3.34
    When I show that recordset field on my web page I'd like it to look like $3.34.

    Is there a way to do it in the sql?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    which database?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's postgresql, with an adodb connection with php. It's currently an integer field since the "money" data type is listed is supposed to be deprecated. I'm not sure if I need to change the field type to something else or if I need to just format the sql statement to output it the way I want.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    integer? then where do the cents come from?

    or are you storing a value of $9.37 as 937?

    use the to_char function
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the heads up on the to_char.

    Regarding the field type. Yeah, I wasn't thinking with the "integer" type. I've just changed it over to "numeric" with a length of 10 and precision of 2. But whatever decimal places I type into my web form always rounds down to the .00 (zero cents). ie. .99 gets saved as 0.00 and .01 gets saved as .00(without applying any of the to_char formatting yet. This is at the actual view of the raw table). Is the "numeric" type not correct either?

  6. #6
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, my mistake. Just a little php work to do. Thanks for the help!


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
  •