Page 1 of 1

Calculation upto a specifed number of digits

Posted: Sat Jul 14, 2012 4:30 pm
by Live24x7
HI

I am working on some formula which results a 2 digit number as output.
The problem is when the result is 0, it returns only one digit that is '0'. I want it to return even 0 in two digits i;e '00'

How is that possible ?

Thanks a lot

Re: Calculation upto a specifed number of digits

Posted: Sat Jul 14, 2012 4:32 pm
by Christopher
I think the function is number_format(), but you can also use sprintf('%02u', $number) or several other similar functions.

Re: Calculation upto a specifed number of digits

Posted: Sat Jul 14, 2012 4:39 pm
by Live24x7
thanks a lot printf('%02u', $number) did the trick :)