Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Math Help

  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    253
    Thanks
    52
    Thanked 3 Times in 3 Posts

    Math Help

    Hey all,


    I was wondering when you come up with a addition or subtraction of numbers with a decimal how you can get the zero or zeros to show up.

    eg.. instead of 139.9

    I would like to see 139.90

    or instead of 300.

    I would like to see 300.00

    Hope ya understand..

    Thanks in advance.


    Slayer.

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,027
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    Use a print formatter:
    PHP Code:
    printf("%0.2f"139.9); 
    If its for monies, then using money_format would be better if you have it available since its locale aware. No matter the case, having 139.90 instead of 139.9 is the difference between (string)139.90 and (double)139.9.

  3. Users who have thanked Fou-Lu for this post:

    SlayerACC (11-07-2012)

  4. #3
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •