Eduardokum\LaravelBoleto\Util::numberFormatValue PHP Method

numberFormatValue() public static method

public static numberFormatValue ( $n, $loop, $insert ) : string
$n
$loop
$insert
return string
    public static function numberFormatValue($n, $loop, $insert)
    {
        return str_pad(self::onlyNumbers(number_format((double) $n, '2', ',', '.')), $loop, $insert, STR_PAD_LEFT);
    }

Same methods

Util::numberFormatValue ( string $n, integer $loop, integer $insert ) : string

Usage Example

Example #1
0
 protected function gerarCodigoBarras()
 {
     if ($this->tipo == self::CEF_TIPO_POS11) {
         $this->codigoBarras = $this->getBanco();
         $this->codigoBarras .= $this->numeroMoeda;
         $this->codigoBarras .= Util::fatorVencimento($this->getDataVencimento());
         $this->codigoBarras .= Util::numberFormatValue($this->getValor(), 10, 0);
         $this->codigoBarras .= $this->gerarNossoNumero();
         $this->codigoBarras .= Util::numberFormatGeral($this->getAgencia(), 4, 0);
         $this->codigoBarras .= Util::numberFormatGeral($this->cedenteCodigo, 11, 0);
     } else {
         if ($this->tipo == self::CEF_TIPO_POS16) {
             $this->codigoBarras = $this->getBanco();
             $this->codigoBarras .= $this->numeroMoeda;
             $this->codigoBarras .= Util::fatorVencimento($this->getDataVencimento());
             $this->codigoBarras .= Util::numberFormatValue($this->getValor(), 10, 0);
             $this->codigoBarras .= substr($this->cedenteCodigo, -5);
             $this->codigoBarras .= $this->getAgencia();
             $this->codigoBarras .= 87;
             $this->codigoBarras .= $this->gerarNossoNumero();
         } else {
             throw new Exception("Tipo do bloqueto inválido");
         }
     }
     $r = Util::modulo11($this->codigoBarras, 9, 1);
     $dv = $r == 0 || $r == 1 || $r == 10 ? 1 : 11 - $r;
     $this->codigoBarras = substr($this->codigoBarras, 0, 4) . $dv . substr($this->codigoBarras, 4);
     $this->carteira = $this->carteiraDesc[$this->getCarteira()];
     return $this->codigoBarras;
 }
All Usage Examples Of Eduardokum\LaravelBoleto\Util::numberFormatValue