Calculation upto a specifed number of digits

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Calculation upto a specifed number of digits

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Calculation upto a specifed number of digits

Post by Christopher »

I think the function is number_format(), but you can also use sprintf('%02u', $number) or several other similar functions.
(#10850)
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: Calculation upto a specifed number of digits

Post by Live24x7 »

thanks a lot printf('%02u', $number) did the trick :)
Post Reply