SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dealing with dollars

    Hi,

    I have created this "site". Well actually, its just a payroll program, not any part of a website, I just decided to write it in php:
    Payroll Program
    To test it, choose any id, and enter about 4 hours per day.. right now, it can't deal if the total amount earned is above 300 dollars because the tax tables it looks up the amount of state and federal tax in only goes up that high (I'll increase it later).

    The problem is that when it computes monetarty values (to it, just numbers) it does it to too many places. I need some way to round off the numbers. For example, it might say that the Social Security Tax is "25.5672" but I need it to say that its "25.57". Even if it doesn't round properly and leaves it as "25.56" thats OK.

    Is there anyway I can do that?

    If anyone should want to see the php code for it, let me know I'm just not sure if I should post it here because it's a bit long.

    Thanks a lot for your help!
    Marc Gugliuzza
    marc.gugliuzza.com



  2. #2
    SitePoint Guru Majglow's Avatar
    Join Date
    Aug 1999
    Location
    B-Town
    Posts
    645
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Does the end result have to be a number? Because you could easily convert the number into a string, than use string editing functions to get rid of the extra decimals.

    That's all that I could think of without looking anything up in the php documentation.

    cArl
    Ohai!

  3. #3
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm new to php so excuse me if I don't make much sense

    Well.. the end result result has to be a number, in the sense that it has to be something like "25.54", but I think once I have the end result in a variable, I can convert that to a string anyway, right?

    Thanks!
    Marc Gugliuzza
    marc.gugliuzza.com



  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use number_format() since thats why they made it.

    http://www.php.net/number_format

    $str = number_format($str, 2);


    This will make two decimals and round accodringly
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Awesome!

    Work's perfectly,

    Thanks a lot! Thanks, too, carl!
    Marc Gugliuzza
    marc.gugliuzza.com




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
  •