Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 902599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:44:35+00:00 2026-05-15T15:44:35+00:00

I need to convert say $89.50 to Eighty-Nine Dollars and Fifty Cents using PHP.

  • 0

I need to convert say $89.50 to Eighty-Nine Dollars and Fifty Cents using PHP. Is there a function I’m missing somewhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:44:36+00:00Added an answer on May 15, 2026 at 3:44 pm

    Here’s a start for you. It’s a recursive function I wrote a while back (part of solving a Project Euler problem 17) that converts numbers to letters… It can handle some pretty big numbers 😉

    All you need to do is add the dollars and cents components and modify according to need. So basically you’d have to call the function once for the dollar amount and once for the cents component. I don’t think there’s a native PHP funciton for this. You’d have to use a library (like Pear) function.

    (You can see the function in action):

    <?php
    function translateToWords($number) 
    {
    /*****
         * A recursive function to turn digits into words
         * Numbers must be integers from -999,999,999,999 to 999,999,999,999 inclussive.    
         *
         *  (C) 2010 Peter Ajtai
         *    This program 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 3 of the License, or
         *    (at your option) any later version.
         *
         *    This program 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.
         *
         *    See the GNU General Public License: <http://www.gnu.org/licenses/>.
         *
         */
        // zero is a special case, it cause problems even with typecasting if we don't deal with it here
        $max_size = pow(10,18);
        if (!$number) return "zero";
        if (is_int($number) && $number < abs($max_size)) 
        {            
            switch ($number) 
            {
                // set up some rules for converting digits to words
                case $number < 0:
                    $prefix = "negative";
                    $suffix = translateToWords(-1*$number);
                    $string = $prefix . " " . $suffix;
                    break;
                case 1:
                    $string = "one";
                    break;
                case 2:
                    $string = "two";
                    break;
                case 3:
                    $string = "three";
                    break;
                case 4: 
                    $string = "four";
                    break;
                case 5:
                    $string = "five";
                    break;
                case 6:
                    $string = "six";
                    break;
                case 7:
                    $string = "seven";
                    break;
                case 8:
                    $string = "eight";
                    break;
                case 9:
                    $string = "nine";
                    break;                
                case 10:
                    $string = "ten";
                    break;            
                case 11:
                    $string = "eleven";
                    break;            
                case 12:
                    $string = "twelve";
                    break;            
                case 13:
                    $string = "thirteen";
                    break;            
                // fourteen handled later
                case 15:
                    $string = "fifteen";
                    break;            
                case $number < 20:
                    $string = translateToWords($number%10);
                    // eighteen only has one "t"
                    if ($number == 18)
                    {
                    $suffix = "een";
                    } else 
                    {
                    $suffix = "teen";
                    }
                    $string .= $suffix;
                    break;            
                case 20:
                    $string = "twenty";
                    break;            
                case 30:
                    $string = "thirty";
                    break;            
                case 40:
                    $string = "forty";
                    break;            
                case 50:
                    $string = "fifty";
                    break;            
                case 60:
                    $string = "sixty";
                    break;            
                case 70:
                    $string = "seventy";
                    break;            
                case 80:
                    $string = "eighty";
                    break;            
                case 90:
                    $string = "ninety";
                    break;                
                case $number < 100:
                    $prefix = translateToWords($number-$number%10);
                    $suffix = translateToWords($number%10);
                    $string = $prefix . "-" . $suffix;
                    break;
                // handles all number 100 to 999
                case $number < pow(10,3):                    
                    // floor return a float not an integer
                    $prefix = translateToWords(intval(floor($number/pow(10,2)))) . " hundred";
                    if ($number%pow(10,2)) $suffix = " and " . translateToWords($number%pow(10,2));
                    $string = $prefix . $suffix;
                    break;
                case $number < pow(10,6):
                    // floor return a float not an integer
                    $prefix = translateToWords(intval(floor($number/pow(10,3)))) . " thousand";
                    if ($number%pow(10,3)) $suffix = translateToWords($number%pow(10,3));
                    $string = $prefix . " " . $suffix;
                    break;
                case $number < pow(10,9):
                    // floor return a float not an integer
                    $prefix = translateToWords(intval(floor($number/pow(10,6)))) . " million";
                    if ($number%pow(10,6)) $suffix = translateToWords($number%pow(10,6));
                    $string = $prefix . " " . $suffix;
                    break;                    
                case $number < pow(10,12):
                    // floor return a float not an integer
                    $prefix = translateToWords(intval(floor($number/pow(10,9)))) . " billion";
                    if ($number%pow(10,9)) $suffix = translateToWords($number%pow(10,9));
                    $string = $prefix . " " . $suffix;    
                    break;
                case $number < pow(10,15):
                    // floor return a float not an integer
                    $prefix = translateToWords(intval(floor($number/pow(10,12)))) . " trillion";
                    if ($number%pow(10,12)) $suffix = translateToWords($number%pow(10,12));
                    $string = $prefix . " " . $suffix;    
                    break;        
                // Be careful not to pass default formatted numbers in the quadrillions+ into this function
                // Default formatting is float and causes errors
                case $number < pow(10,18):
                    // floor return a float not an integer
                    $prefix = translateToWords(intval(floor($number/pow(10,15)))) . " quadrillion";
                    if ($number%pow(10,15)) $suffix = translateToWords($number%pow(10,15));
                    $string = $prefix . " " . $suffix;    
                    break;                    
            }
        } else
        {
            echo "ERROR with - $number<br/> Number must be an integer between -" . number_format($max_size, 0, ".", ",") . " and " . number_format($max_size, 0, ".", ",") . " exclussive.";
        }
        return $string;    
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In PHP, I need a function to convert a querystring from an URL, say:
Let's say I have an integer that I need to convert to a string
I need to convert a Word document into HTML file(s) in Java. The function
I need to convert the file path in windows say C:\Documents and Settings\Manoj\Desktop for
Let's say that I have like this: \\n , I need to convert it
Say I have a string phone = 1-800-test I need to convert the letters
I need to reformat a string using jQuery or vanilla JavaScript Let’s say we
I've determined that I need to convert a Windows FILETIME type to something PHP
I need to convert integer value into char array on bit layer. Let's say
I need to convert latitude/longitude coordinates into Easting/Northing coordinates in the Alberta 10 TM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.