public static function number_to_word($number)
    {
        $number = (string) $number;

        if (strpos($number, '.') !== false) {
            list($number, $decimal) = explode('.', $number);
        } else {
            $decimal = false;
        }

        $output = '';

        if ($number[0] == '-') {
            $output = 'negative ';
            $number = ltrim($number, '-');
        } elseif ($number[0] == '+') {
            $output = 'positive ';
            $number = ltrim($number, '+');
        }

        if ($number[0] == '0') {
            $output .= 'zero';
        } else {
            $length = 19;
            $number = str_pad($number, 60, '0', STR_PAD_LEFT);
            $group  = rtrim(chunk_split($number, 3, ' '), ' ');
            $groups = explode(' ', $group);
            $groups2 = array();

            foreach ($groups as $group) {
                $group[1] = isset($group[1]) ? $group[1] : null;
                $group[2] = isset($group[2]) ? $group[2] : null;
                $groups2[] = self::numberToWordThreeDigits($group[0], $group[1], $group[2]);
            }

            for ($z = 0; $z < count($groups2); $z++) {
                if ($groups2[$z] != '') {
                    $output .= $groups2[$z] . self::numberToWordConvertGroup($length - $z);
                    $output .= ($z < $length && ! array_search('', array_slice($groups2, $z + 1, -1)) && $groups2[$length] != '' && $groups[$length][0] == '0' ? ' and ' : ', ');
                }
            }

            $output = rtrim($output, ', ');
        }

        if ($decimal > 0) {
            $output .= ' point';

            for ($i = 0; $i < strlen($decimal); $i++) {
                $output .= ' ' . self::numberToWordConvertDigit($decimal[$i]);
            }
        }

        return $output;
    }
public static function number_to_word($number)
    {
        $number = (string) $number;

        if (strpos($number, '.') !== false) {
            list($number, $decimal) = explode('.', $number);
        } else {
            $decimal = false;
        }

        $output = '';

        if ($number[0] == '-') {
            $output = 'negative ';
            $number = ltrim($number, '-');
        } elseif ($number[0] == '+') {
            $output = 'positive ';
            $number = ltrim($number, '+');
        }

        if ($number[0] == '0') {
            $output .= 'zero';
        } else {
            $length = 19;
            $number = str_pad($number, 60, '0', STR_PAD_LEFT);
            $group  = rtrim(chunk_split($number, 3, ' '), ' ');
            $groups = explode(' ', $group);
            $groups2 = array();

            foreach ($groups as $group) {
                $group[1] = isset($group[1]) ? $group[1] : null;
                $group[2] = isset($group[2]) ? $group[2] : null;
                $groups2[] = self::numberToWordThreeDigits($group[0], $group[1], $group[2]);
            }

            for ($z = 0; $z < count($groups2); $z++) {
                if ($groups2[$z] != '') {
                    $output .= $groups2[$z] . self::numberToWordConvertGroup($length - $z);
                    $output .= ($z < $length && ! array_search('', array_slice($groups2, $z + 1, -1)) && $groups2[$length] != '' && $groups[$length][0] == '0' ? ' and ' : ', ');
                }
            }

            $output = rtrim($output, ', ');
        }

        if ($decimal > 0) {
            $output .= ' point';

            for ($i = 0; $i < strlen($decimal); $i++) {
                $output .= ' ' . self::numberToWordConvertDigit($decimal[$i]);
            }
        }

        return $output;
    }
public static function number_to_word ( $ number ) { $ number = ( string ) $ number ; if ( strpos ( $ number , '.' ) !== false ) { list ( $ number , $ decimal ) = explode ( '.' , $ number ) ; } else { $ decimal = false ; } $ output = '' ; if ( $ number [ 0 ] == '-' ) { $ output = 'negative ' ; $ number = ltrim ( $ number , '-' ) ; } elseif ( $ number [ 0 ] == '+' ) { $ output = 'positive ' ; $ number = ltrim ( $ number , '+' ) ; } if ( $ number [ 0 ] == '0' ) { $ output .= 'zero' ; } else { $ length = 19 ; $ number = str_pad ( $ number , 60 , '0' , STR_PAD_LEFT ) ; $ group = rtrim ( chunk_split ( $ number , 3 , ' ' ) , ' ' ) ; $ groups = explode ( ' ' , $ group ) ; $ groups2 = array ( ) ; foreach ( $ groups as $ group ) { $ group [ 1 ] = isset ( $ group [ 1 ] ) ? $ group [ 1 ] : null ; $ group [ 2 ] = isset ( $ group [ 2 ] ) ? $ group [ 2 ] : null ; $ groups2 [ ] = self :: numberToWordThreeDigits ( $ group [ 0 ] , $ group [ 1 ] , $ group [ 2 ] ) ; } for ( $ z = 0 ; $ z < count ( $ groups2 ) ; $ z ++ ) { if ( $ groups2 [ $ z ] != '' ) { $ output .= $ groups2 [ $ z ] . self :: numberToWordConvertGroup ( $ length - $ z ) ; $ output .= ( $ z < $ length && ! array_search ( '' , array_slice ( $ groups2 , $ z + 1 , - 1 ) ) && $ groups2 [ $ length ] != '' && $ groups [ $ length ] [ 0 ] == '0' ? ' and ' : ', ' ) ; } } $ output = rtrim ( $ output , ', ' ) ; } if ( $ decimal > 0 ) { $ output .= ' point' ; for ( $ i = 0 ; $ i < strlen ( $ decimal ) ; $ i ++ ) { $ output .= ' ' . self :: numberToWordConvertDigit ( $ decimal [ $ i ] ) ; } } return $ output ; }
Converts a number into the text equivalent. For example, 456 becomes four
hundred and fifty-six.

Part of the IntToWords Project.

@param  int|float $number The number to convert into text
@return string
Converts a number into the text equivalent . For example 456 becomes four hundred and fifty - six .