qwertz qwertz - 1 year ago 116
PHP Question

PHP zerofill number without losing decimals

how can I zerofill a number without loosing decimals?
I tried using sprintf but it deleted all my decimals, what I don't want.

I have the number 12.2 and I want it to look like 012.2, but sprintf gives me 012 and removes the decimals. The function I'm using is:

sprintf('%02u', $number);

Answer Source

You have a good explanation of the sprintf format in the PHP manual, which applies to printf as well.

printf('%05.1f', 12.2);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download