#1
  1. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    PHP provides a round function, but I see no reference to "padding"..

    as with most "dollar" figures, we like to add those ".00" cents on it..

    any assist would be appreciated.

    thanks in advance.

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    Hi there

    <?php $num=450;
    $num=number_format($num,2);
    echo $num ;?> displays 450.00

    note that $num is now a string!



    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    $num *= 100;
    $num = round($num);
    $num /= 100;

    [/code]
    ex. If num was 123.9856 it would first take it times 100

    123.9856*100=12398.56

    then round

    12399

    Then divide by 100

    12399/100=123.99

    I really used that for a Javascript but it should work just the same.


    [This message has been edited by Aoeex (edited July 02, 2000).]
  6. #4
  7. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks to both fo you for the help, these were just what I was looking for.

    I went back through a couple of my perl scripts, and saw that I had a round/pad sub routine in one of my libraries.

    but man they're lengthy in Perl.

    besides, I recently re-wrote one of my perl programs in PHP.. it's actually rather amazing at just how much easier it is to do things in PHP (vs) Perl.

    Now, if I could figure out the imap_fetchstructure() and sending an attachment file via the "mail()" or imap_mail() functions, I'd have it made

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  8. #5
  9. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>but man they're lengthy in Perl
    There are thousands of Perl modules out there awaiting to be discovered by you.

    Go to http://www.perl.com/CPAN-local/modul...module/Number/ and download -> Number-Format-1.42.tar.gz

    #############################################
    #!/usr/local/bin/perl
    print "Content-type: text/htmlnn";
    $number = '450';
    use Number::Format qw(:subs);
    $number = format_price($number);
    print "$numbern";

    With Number.pm, not only can you convert price format, to name just a few, picture, number and bytes.
    its "format_bytes" can do thing many might have asked.
    it converts 123,456,789 bytes to megabytes.
    As simple as this one line code:
    $formatted = format_bytes($number, $precision);

    >>it's actually rather amazing at just how much easier
    >>it is to do things in PHP (vs) Perl
    Not trying to start a flame war here, PHP is not always faster and easier than Perl, it totally depends on the complexity of its tasks. "sending an attachment file" could be easily done using Perl module. You should check out http://www.perl.com/CPAN-local/modules/by-module/ if you haven't.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    14
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Robert_J_Sherman:
    PHP provides a round function, but I see no reference to "padding"..

    as with most "dollar" figures, we like to add those ".00" cents on it..

    any assist would be appreciated.

    thanks in advance.

    [/quote]

    You can also do this:

    <?php
    $price = 10;
    $fmt_price = sprintf("%0.2f",$price);
    echo "<P>The price is $$fmt_price.</p>";
    ?>

    Prints: The price is $10.00.



    ------------------
    From the day we're born, we're running out of time.
  12. #7
  13. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    I've written quite a few web apps in Perl in the last couple of years.

    In many ways, I've found PHP to be a breath of fresh air.

    I'm certainly not trying to say PHP is better than Perl.

    I just find it a bit easier and most of the PHP code I've written lately has been done in about half the time it would have taken in Perl...

    That could be either because I'm just getting really good, or that PHP is simpler to pick up on and learn.. dunno which

    No flamming here, not at all.. I've got a rather open mind to other's opinions, shoot we all have em' and about the only one that never stinks is our own

    In truth I feel I've learned a lot in the last 3 years, just from listening to others ideas.

    To be frank, I think I switched over because I wanted something that I could write on win32 (for testing) and upload to the host (Unix) with little change(s) to the code.

    Just seemed like the best choice.

    Granted, our host uses both, and so do I.

    Perl will be around for a long time, and I really think PHP is here to stay, and it can only get better.

    I just wish I could build4.0.1 to work on my system, and those darn libraries.. I can only get three of them to load without giving off big errors (FATAL ERROR, a device wasn't found..blah blah)..

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.

Similar Threads

  1. Replies: 2
    Last Post: August 18th, 2004, 10:45 PM
  2. Replies: 4
    Last Post: January 28th, 2004, 08:29 AM
  3. PHP with UnixODBC
    By coder4hire in forum PHP Development
    Replies: 2
    Last Post: January 20th, 2004, 01:14 PM
  4. Passing string from PHP to Javascript
    By ka8oad in forum JavaScript Development
    Replies: 4
    Last Post: January 17th, 2004, 03:12 PM
  5. UnixODBC + PHP + Apache + Empress
    By coder4hire in forum Database Management
    Replies: 0
    Last Post: January 15th, 2004, 01:41 PM

IMN logo majestic logo threadwatch logo seochat tools logo