SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    trailing zeros in double

    how do i get the trailing zero to print in the following scenario:

    PHP Code:
    $price 0.70;

    print 
    $price
    this will print simply 0.7. but i need it to print 0.70.

    sorry if this sounds dumb, been having a tough day. cheers!

  2. #2
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $money1 = 68.75;
    $money2 = 54.35;
    $money = $money1 + $money2;
    // echo $money will output "123.1";
    $formatted = sprintf("%01.2f", $money);
    // echo $formatted will output "123.10"
    http://www.php.net/manual/en/function.fprintf.php

  3. #3
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you can just use number_format.
    PHP Code:

    $price 
    0.70;
    echo 
    number_format($price2); 
    http://www.php.net/manual/en/function.number-format.php

  4. #4
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you 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
  •