src/Util.php
public static function nFloat($number, $decimals = 2, $showThousands = false)
    {
        if (is_null($number) || empty(self::onlyNumbers($number)) || floatval($number) == 0) {
            return 0;
        }
        $pontuacao = preg_replace('/[0-9]/', '', $number);
        $locale = (mb_substr($pontuacao, -1, 1) == ',') ? "pt-BR" : "en-US";
        $formater = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);

        if ($decimals === false) {
            $decimals = 2;
            preg_match_all('/[0-9][^0-9]([0-9]+)/', $number, $matches);
            if (!empty($matches[1])) {
                $decimals = mb_strlen(rtrim($matches[1][0], 0));
            }
        }

        return number_format($formater->parse($number, \NumberFormatter::TYPE_DOUBLE), $decimals, '.', ($showThousands ? ',' : ''));
    }
public static function nFloat($number, $decimals = 2, $showThousands = false)
    {
        if (is_null($number) || empty(self::onlyNumbers($number)) || floatval($number) == 0) {
            return 0;
        }
        $pontuacao = preg_replace('/[0-9]/', '', $number);
        $locale = (mb_substr($pontuacao, -1, 1) == ',') ? "pt-BR" : "en-US";
        $formater = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);

        if ($decimals === false) {
            $decimals = 2;
            preg_match_all('/[0-9][^0-9]([0-9]+)/', $number, $matches);
            if (!empty($matches[1])) {
                $decimals = mb_strlen(rtrim($matches[1][0], 0));
            }
        }

        return number_format($formater->parse($number, \NumberFormatter::TYPE_DOUBLE), $decimals, '.', ($showThousands ? ',' : ''));
    }
public static function nFloat ( $ number , $ decimals = 2 , $ showThousands = false ) { if ( is_null ( $ number ) || empty ( self :: onlyNumbers ( $ number ) ) || floatval ( $ number ) == 0 ) { return 0 ; } $ pontuacao = preg_replace ( '/[0-9]/' , '' , $ number ) ; $ locale = ( mb_substr ( $ pontuacao , - 1 , 1 ) == ',' ) ? "pt-BR" : "en-US" ; $ formater = new \ NumberFormatter ( $ locale , \ NumberFormatter :: DECIMAL ) ; if ( $ decimals === false ) { $ decimals = 2 ; preg_match_all ( '/[0-9][^0-9]([0-9]+)/' , $ number , $ matches ) ; if ( ! empty ( $ matches [ 1 ] ) ) { $ decimals = mb_strlen ( rtrim ( $ matches [ 1 ] [ 0 ] , 0 ) ) ; } } return number_format ( $ formater -> parse ( $ number , \ NumberFormatter :: TYPE_DOUBLE ) , $ decimals , '.' , ( $ showThousands ? ',' : '' ) ) ; }
Mostra o Valor no float Formatado

@param  string  $number
@param  integer $decimals
@param  boolean $showThousands
@return string
Mostra o Valor no float Formatado