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 4 of 4

Thread: printf

  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    printf

    so let's say that a variable $num can be the floats 13, 5.375, 5.24.

    How do I format it so that it would appear 13, 5.375, 5.24?

    I tried using just %f but it would have lots of 0's in the end (13.0000000000).

    Using echo would work, but I have other numbers that need to use the formating.

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Have you tried %.3f, this will display at a maximum of 3 decimal places.

    See if it helps
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It will show 13.000 for the number 13.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Why do you need to use printf() as opposed to (float) $num or floatval($num)?


  •  

    Posting Permissions

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