[ create a new paste ] login | about

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

PHP, pasted on Jul 8:
1
2
3
4
5
6
7
8
9
10
11
<?php
function padIntegerPart($n, $len) {
    $intPart = (int)$n;

    return str_repeat('0', max(0, $len - 1 - floor(log($intPart, 10)))) . $n;
}

echo padIntegerPart(2.11, 1)."\n";
echo padIntegerPart(2.11, 2)."\n";
echo padIntegerPart(2.11, 3)."\n";
?>


Output:
1
2
3
2.11
02.11
002.11


Create a new paste based on this one


Comments: