SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Turn string to dollar equivalant

    Greetings.

    I'm simply needing to turn a string such as ->

    '001059'

    To a dollar amount

    $10.59

    I've managed to lose the leading 0's thanks to trim() - but after trying float and floatval neither work for me.

    Any suggestions.

    thanks
    jw

  2. #2
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    managed to do this simply by multiply * .01 but there has to be a more professional way of doing this.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $number_f  = 1059 * .01;
    echo "$".number_format($number_f, 2, '.', ',');
    //prints $10.59

    Not really sure if this helps you at all. It just makes the formatting clean.

  4. #4
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks mk

  5. #5
    SitePoint Zealot krt's Avatar
    Join Date
    Sep 2005
    Location
    Australia
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or money_format(), exactly for this purpose:
    http://php.net/function.money-format


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
  •