note 46795 deleted from function.number-format by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 23 Oct 2004 16:50:21 +0000 |
| Subject: | note 46795 deleted from function.number-format by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79002@lists.php.net to get a copy of this message | ||
Note Submitter: jorisbots at hotmail dot com
----
addition to the above mentioned function leading_zero:
if 0 is entered it will return a 0 with leading 0's. (I needed that with a time-editing form)
function leading_zero( $aNumber, $intPart, $floatPart=NULL, $dec_point=NULL, $thousands_sep=NULL) {
//Note: The $thousands_sep has no real function because it will be "disturbed" by
plain leading zeros -> the main goal of the function
$formattedNumber = $aNumber;
if (!is_null($floatPart)) { //without 3rd parameters the "float part" of the float
shouldn't be touched
$formattedNumber = number_format($formattedNumber, $floatPart, $dec_point, $thousands_sep);
}
//if ($intPart > floor(log10($formattedNumber)))
$formattedNumber = str_repeat("0",($intPart + -1 -
floor(log10($formattedNumber)))).$formattedNumber;
if($formattedNumber==0)
{
$formattedNumber = "0";
for($i=1;$i<$intPart;$i++)
$formattedNumber .="0";
}
return $formattedNumber;
}