[ create a new paste ] login | about

Link: http://codepad.org/FiNeA2mf    [ raw code | output | fork ]

PHP, pasted on Jul 8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

function pad($n) {
    $n = explode('.', (string)$n);
    
    if (2 === count($n)) {
        return sprintf("%02d.%d\n", $n[0], $n[1]);    
    }

    return sprintf("%02d\n", $n[0]);    
}

foreach (array(2, 22, 222, 2., 2.11) as $num) {
    echo pad($num);
}


Output:
1
2
3
4
5
02
22
222
02
02.11


Create a new paste based on this one


Comments: