I have been sending out checks with the dollar amount printed in words, ignoring the cents. This was OK for three (3) months. Now the bank tells me that I have to include the cents, if any, on the same line as the dollar amount in word. The cents can be in numerals but they must be there. I have been using a php script thus far to convert the dollars to words.

Is there a simple script available that can do that without me reinventing the wheel? i.e. two hundred thirty one dollars and 68 cents.

    I really don't want to get into PEAR. Is there another way?

      nogeekyet;10960193 wrote:

      I really don't want to get into PEAR.

      Why?

      nogeekyet;10960193 wrote:

      Is there another way?

      Of course; since you apparently don't want to "get into" a pre-made solution, you could always write your own class/function/whatever from scratch to do this.

        Yes I like to re-invent the wheel. Here is what I did:

        function convert_number($number) 
        { 
            if (($number < 0) || ($number > 999999999)) 
            { 
                return "$number"; 
            } 
        
        $Gn = floor($number / 1000000);  /* Millions (giga) */ 
        $number -= $Gn * 1000000; 
        $kn = floor($number / 1000);     /* Thousands (kilo) */ 
        $number -= $kn * 1000; 
        $Hn = floor($number / 100);      /* Hundreds (hecto) */ 
        $number -= $Hn * 100; 
        $Dn = floor($number / 10);       /* Tens (deca) */ 
        $n = $number % 10;               /* Ones */ 
        
        $res = ""; 
        
        if ($Gn) 
        { 
            $res .= convert_number($Gn) . " Million"; 
        } 
        
        if ($kn) 
        { 
            $res .= (empty($res) ? "" : " ") . 
                convert_number($kn) . " Thousand"; 
        } 
        
        if ($Hn) 
        { 
            $res .= (empty($res) ? "" : " ") . 
                convert_number($Hn) . " Hundred"; 
        } 
        
        $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", 
            "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", 
            "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", 
            "Nineteen"); 
        $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", 
            "Seventy", "Eigthy", "Ninety"); 
        
        if ($Dn || $n) 
        { 
            if (!empty($res)) 
            { 
        //            $res .= " and "; 
                   $res .= " "; 
                } 
        
            if ($Dn < 2) 
            { 
                $res .= $ones[$Dn * 10 + $n]; 
            } 
            else 
            { 
                $res .= $tens[$Dn]; 
        
                if ($n) 
                { 
                    $res .= "-" . $ones[$n]; 
                } 
            } 
        } 
        
        if (empty($res)) 
        { 
            $res = "zero"; 
        } 
        
        return $res; 
        } 
        
        $USDollar = number_format($TotNet, 2,'.',','); // put it in decimal format, rounded 
        
        $printTotNet = convert_number($TotNet);  //convert to words (see function above) 
        $table .= '*********** '; 
        $x = $USDollar; 
        $explode = explode('.', $x);   //separate the cents 
        $printDolCents = $printTotNet . ' Dollars and ' . $explode[1] . ' Cents ***'; 
        $table .= $printDolCents;  // print the line with dollars words and cents in numerals
        

        Thanks

          Write a Reply...