original_string: protected function formatNumberWithPattern($pattern, $value, $maximumFractionDigits=0, $minimumFractionDigits=0)
      {
          if (!is_numeric($value)) {
              return $value;
          }
  
          $usesGrouping = (strpos($pattern, ',') !== false);
          // if pattern has number groups, parse them.
          if ($usesGrouping) {
              preg_match('/#+0/', $pattern, $primaryGroupMatches);
              $primaryGroupSize = $secondaryGroupSize = strlen($primaryGroupMatches[0]);
              $numberGroups = explode(',', $pattern);
              // check for distinct secondary group size.
              if (count($numberGroups) > 2) {
                  $secondaryGroupSize = strlen($numberGroups[1]);
              }
          }
  
          // Ensure that the value is positive and has the right number of digits.
          $negative = $this->isNegative($value);
          $signMultiplier = $negative ? '-1' : '1';
          $value = $value / $signMultiplier;
          $value = round($value, $maximumFractionDigits);
          // Split the number into major and minor digits.
          $valueParts = explode('.', $value);
          $majorDigits = $valueParts[0];
          // Account for maximumFractionDigits = 0, where the number won't
          // have a decimal point, and $valueParts[1] won't be set.
          $minorDigits = isset($valueParts[1]) ? $valueParts[1] : '';
          if ($usesGrouping) {
              // Reverse the major digits, since they are grouped from the right.
              $majorDigits = array_reverse(str_split($majorDigits));
              // Group the major digits.
              $groups = array();
              $groups[] = array_splice($majorDigits, 0, $primaryGroupSize);
              while (!empty($majorDigits)) {
                  $groups[] = array_splice($majorDigits, 0, $secondaryGroupSize);
              }
              // Reverse the groups and the digits inside of them.
              $groups = array_reverse($groups);
              foreach ($groups as &$group) {
                  $group = implode(array_reverse($group));
              }
              // Reconstruct the major digits.
              $majorDigits = implode(',', $groups);
          }
          if ($minimumFractionDigits < $maximumFractionDigits) {
              // Strip any trailing zeroes.
              $minorDigits = rtrim($minorDigits, '0');
              if (strlen($minorDigits) < $minimumFractionDigits) {
                  // Now there are too few digits, re-add trailing zeroes
                  // until the desired length is reached.
                  $neededZeroes = $minimumFractionDigits - strlen($minorDigits);
                  $minorDigits .= str_repeat('0', $neededZeroes);
              }
          }
          // Assemble the final number and insert it into the pattern.
          $value = $minorDigits ? $majorDigits . '.' . $minorDigits : $majorDigits;
          $value = preg_replace('/#(?:[\.,]#+)*0(?:[,\.][0#]+)*/', $value, $pattern);
          // Localize the number.
          $value = $this->replaceSymbols($value);
          return $value;
      }
code: protected function formatNumberWithPattern($pattern, $value, $maximumFractionDigits=0, $minimumFractionDigits=0)
      {
          if (!is_numeric($value)) {
              return $value;
          }
  
          $usesGrouping = (strpos($pattern, ',') !== false);
          // if pattern has number groups, parse them.
          if ($usesGrouping) {
              preg_match('/#+0/', $pattern, $primaryGroupMatches);
              $primaryGroupSize = $secondaryGroupSize = strlen($primaryGroupMatches[0]);
              $numberGroups = explode(',', $pattern);
              // check for distinct secondary group size.
              if (count($numberGroups) > 2) {
                  $secondaryGroupSize = strlen($numberGroups[1]);
              }
          }
  
          // Ensure that the value is positive and has the right number of digits.
          $negative = $this->isNegative($value);
          $signMultiplier = $negative ? '-1' : '1';
          $value = $value / $signMultiplier;
          $value = round($value, $maximumFractionDigits);
          // Split the number into major and minor digits.
          $valueParts = explode('.', $value);
          $majorDigits = $valueParts[0];
          // Account for maximumFractionDigits = 0, where the number won't
          // have a decimal point, and $valueParts[1] won't be set.
          $minorDigits = isset($valueParts[1]) ? $valueParts[1] : '';
          if ($usesGrouping) {
              // Reverse the major digits, since they are grouped from the right.
              $majorDigits = array_reverse(str_split($majorDigits));
              // Group the major digits.
              $groups = array();
              $groups[] = array_splice($majorDigits, 0, $primaryGroupSize);
              while (!empty($majorDigits)) {
                  $groups[] = array_splice($majorDigits, 0, $secondaryGroupSize);
              }
              // Reverse the groups and the digits inside of them.
              $groups = array_reverse($groups);
              foreach ($groups as &$group) {
                  $group = implode(array_reverse($group));
              }
              // Reconstruct the major digits.
              $majorDigits = implode(',', $groups);
          }
          if ($minimumFractionDigits < $maximumFractionDigits) {
              // Strip any trailing zeroes.
              $minorDigits = rtrim($minorDigits, '0');
              if (strlen($minorDigits) < $minimumFractionDigits) {
                  // Now there are too few digits, re-add trailing zeroes
                  // until the desired length is reached.
                  $neededZeroes = $minimumFractionDigits - strlen($minorDigits);
                  $minorDigits .= str_repeat('0', $neededZeroes);
              }
          }
          // Assemble the final number and insert it into the pattern.
          $value = $minorDigits ? $majorDigits . '.' . $minorDigits : $majorDigits;
          $value = preg_replace('/#(?:[\.,]#+)*0(?:[,\.][0#]+)*/', $value, $pattern);
          // Localize the number.
          $value = $this->replaceSymbols($value);
          return $value;
      }
code_tokens: protected function formatNumberWithPattern ( $ pattern , $ value , $ maximumFractionDigits = 0 , $ minimumFractionDigits = 0 ) { if ( ! is_numeric ( $ value ) ) { return $ value ; } $ usesGrouping = ( strpos ( $ pattern , ',' ) !== false ) ; // if pattern has number groups, parse them. if ( $ usesGrouping ) { preg_match ( '/#+0/' , $ pattern , $ primaryGroupMatches ) ; $ primaryGroupSize = $ secondaryGroupSize = strlen ( $ primaryGroupMatches [ 0 ] ) ; $ numberGroups = explode ( ',' , $ pattern ) ; // check for distinct secondary group size. if ( count ( $ numberGroups ) > 2 ) { $ secondaryGroupSize = strlen ( $ numberGroups [ 1 ] ) ; } } // Ensure that the value is positive and has the right number of digits. $ negative = $ this -> isNegative ( $ value ) ; $ signMultiplier = $ negative ? '-1' : '1' ; $ value = $ value / $ signMultiplier ; $ value = round ( $ value , $ maximumFractionDigits ) ; // Split the number into major and minor digits. $ valueParts = explode ( '.' , $ value ) ; $ majorDigits = $ valueParts [ 0 ] ; // Account for maximumFractionDigits = 0, where the number won't // have a decimal point, and $valueParts[1] won't be set. $ minorDigits = isset ( $ valueParts [ 1 ] ) ? $ valueParts [ 1 ] : '' ; if ( $ usesGrouping ) { // Reverse the major digits, since they are grouped from the right. $ majorDigits = array_reverse ( str_split ( $ majorDigits ) ) ; // Group the major digits. $ groups = array ( ) ; $ groups [ ] = array_splice ( $ majorDigits , 0 , $ primaryGroupSize ) ; while ( ! empty ( $ majorDigits ) ) { $ groups [ ] = array_splice ( $ majorDigits , 0 , $ secondaryGroupSize ) ; } // Reverse the groups and the digits inside of them. $ groups = array_reverse ( $ groups ) ; foreach ( $ groups as & $ group ) { $ group = implode ( array_reverse ( $ group ) ) ; } // Reconstruct the major digits. $ majorDigits = implode ( ',' , $ groups ) ; } if ( $ minimumFractionDigits < $ maximumFractionDigits ) { // Strip any trailing zeroes. $ minorDigits = rtrim ( $ minorDigits , '0' ) ; if ( strlen ( $ minorDigits ) < $ minimumFractionDigits ) { // Now there are too few digits, re-add trailing zeroes // until the desired length is reached. $ neededZeroes = $ minimumFractionDigits - strlen ( $ minorDigits ) ; $ minorDigits .= str_repeat ( '0' , $ neededZeroes ) ; } } // Assemble the final number and insert it into the pattern. $ value = $ minorDigits ? $ majorDigits . '.' . $ minorDigits : $ majorDigits ; $ value = preg_replace ( '/#(?:[\.,]#+)*0(?:[,\.][0#]+)*/' , $ value , $ pattern ) ; // Localize the number. $ value = $ this -> replaceSymbols ( $ value ) ; return $ value ; }
docstring: Formats the given number with the given pattern
  
  @param string $pattern
  @param string|int|float $value
  @param int $maximumFractionDigits
  @param int $minimumFractionDigits
  @return mixed|string
docstring_tokens: Formats the given number with the given pattern