Location: PHPKode > projects > FiForms Framework > FiForms/FiForms-includes/FiChecks_numberWords.inc.php
<?php
/*
*******************************************************************************

    FiChecks -- PHP Class to generate printable checks via PDF 

    Copyright (C) 2004  Daniel McFeeters

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    The original author of this library can be contacted at the following 
    address:

    Daniel McFeeters
    182 Baker Rd.
    Faubush, KY 42544-6526
    email:databases at alltel dot net


Project Started May 14, 2004
*******************************************************************************
numberWords Class Library

Library to convert a number (1234) into words 
(One Thousand Two Hundred Thirty Four)
*******************************************************************************
*/

    class numberWords
    {
        var $numbers; // array of numbers
        function numberWords()
        {
            $this->numbers = array(
            0 => '',
            1 => 'One',
            2 => 'Two',
            3 => 'Three',
            4 => 'Four',
            5 => 'Five',
            6 => 'Six',
            7 => 'Seven',
            8 => 'Eight',
            9 => 'Nine',
            10 => 'Ten',
            11 => 'Eleven',
            12 => 'Twelve',
            13 => 'Thirteen',
            14 => 'Fourteen',
            15 => 'Fifteen',
            16 => 'Sixteen',
            17 => 'Seventeen',
            18 => 'Eighteen',
            19 => 'Nineteen',
            20 => 'Twenty',
            30 => 'Thirty',
            40 => 'Fourty',
            50 => 'Fifty',
            60 => 'Sixty',
            70 => 'Seventy',
            80 => 'Eighty',
            90 => 'Ninety',
            100 => 'Hundred',
            1000 => 'Thousand',
            1000000 => 'Million');
            
        } // function numberWords

        function tens($number)
        // accepts a number between 1 and 99 and converts to words
        {
            if($number < 20)
            {
                $words = $this->numbers[$number];
            }
            else
            {
                $words = $this->numbers[floor($number/10)*10].' '.
                         $this->numbers[$number % 10];
            }
            return($words);
        }

        function hundreds($number)
        {
            if($number < 100)
            {
                $words = $this->tens($number);
            }
            else
            {
                $words = $this->numbers[floor($number/100)].' '.
                    $this->numbers[100].' '.$this->tens($number % 100);
            }
            return($words);
        }

        function thousands($number)
        {
            if($number < 1000)
            {
                $words = $this->hundreds($number);
            }
            else
            {
                $words = $this->hundreds(floor($number/1000)).' '.
                    $this->numbers[1000].' '.$this->hundreds($number % 1000);
            }
            return($words);
        }
        
        function millions($number)
        {
            if($number < 1000000)
            {
                $words = $this->thousands($number);
            }
            else
            {
                $words = $this->hundreds(floor($number/1000000)).' '.
                    $this->numbers[1000000].' '.$this->thousands($number % 1000000);
            }
            return($words);
        }
        
        function toWords($number)
        // converts any whole number into words
        {
            $theNumber = (int)$number;
            if($theNumber < 1000000000 && $theNumber >= 0)
            {
                return($this->millions($theNumber));
            }
            else
            {
                return "VOID";
            }
        }
        
    }  // class numberWords
?>
Return current item: FiForms Framework