SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there!

    I have the following code...

    $string1 = 40.10;
    $string2 = 0.70;
    $holder = $string1 + $string2;

    when I echo $holder, I get 40.8

    Is there any way that I can keep the trailing "0" at the end so that it reads 40.80 ?

    Thanks,

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are familiar with the C language functions of printf() and sprintf() then they work the same way in PHP.

    If you are not (like me ) then use number_format()
    http://us4.php.net/manual/en/function.number-format.php

    echo number_format($holder, 2);

  3. #3
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I looked for ages at PHP.net for a function that would do this. Can't have looked hard enough!

    Thanks again freakysid, you're a star.


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
  •