View Full Version : printf

03-05-2008, 05:27 AM
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.

03-05-2008, 05:37 AM
Have you tried %.3f, this will display at a maximum of 3 decimal places.

See if it helps :D

03-05-2008, 06:18 AM
It will show 13.000 for the number 13.

03-05-2008, 06:42 AM
Why do you need to use printf() (http://php.net/printf) as opposed to (float) $num or floatval($num) (http://php.net/floatval)?